PYTHON DEFINITIONS Flashcards
Primitives
o Numbers
o Strings
o Booleans
Numbers
values that allow us to do calculations and keep count.
Strings
Are any sequence of characters (letters, spaces, numbers, or symbols). used to represent text or speech.
“Hello World”
Boolean
represent one of two values, true and false.
Operators
Are different symbols that represent an operation, such as the plus sign (+) as a symbol for addition.
Operations enable us to process our data, to transform it into something else.
Operating in Program include
*Making calculations using arithmetic operators.
*Comparing information using comparison operators.
*Creating logical expressions using logical (aka Boolean) operators.
Arithmetic Operators
Performs Calculations
+, -, *, /
Comparison Operators
Comparing values and evaluate their relationship
Less than < — value to the left is less than the value to the right: 2 < 6
Greater than > — value to the left is more than the value to the right: 14 > 5
Equals == — value
Tuple
is an ordered sequence of objects or characters separated by commas with parentheses on either side of the sequence.
mytuple= (7,”u”,”p”,1,”e”)
Strings & Tuple
Both immutable / you can’t update the data once you create it.
Variable
Stores your data information
mycoffee:
Dictionaries
Stores data as a collections of key-value pairs.
menu= {“avocado toast”: 6, “carrot juice”:5, “blueberry muffin”]
menu = dictionary
avocado toast , 6 = key-value pair (comparing both vaules)
Interger
Whole number without decimals
Control Flow
Control flow is the order in which instructions are executed.
List
Used to store multiple items in a single variable.
[2,4,6,8,10,12]
Logical /Boolean Operators
*AND — both expressions evaluate to true, so the final result is true:
o ((4 > 1) AND (2 < 7)) is the same as (TRUE AND TRUE).
AND/ OR / NOT
Float
Numbers with decimals
Arrays
Is a variable that can store more than one method at a time.
It is used to store a collection of data.
EXAMPLE:
Variable = A
Value = 1-100
A (0), A (1), A (2), A (3)
Example:
append() = add an element at the end of the list
clear() = remove all copy
copy()= return all copies to a list
array (‘i’, [1,2,3,4,5,])
for numbers in numbers:
print(numbers)
NOTE: indexing values start from 0 and then 1
Index
The INDEX function returns a value or the reference to a value from within a table or range.
()
Advantages of an Array
Save memory in your system.
Array’s don’t slow down your memory or cache because the system recognize it as one big function rather than an individual “list” or “table.”
Arrays value are near each other in memory. It’s easy to transfer from Cache to CPU.
Loops
A segment of code that executes multiple times.
Iteration
the process in which the code is executed once.
Used in Loops
EXAMPLE:
numbers = [0, 254, 2, -1, 3]
for num in numbers:
if (num < 0):
print(“Negative number detected!”)
break
print(num)
OUTPUT:
0
254
2
Negative number detected!
Function
A function is a block of code which only runs when it is called.
A function is a named sequence of instructions, packaged as a unit, that performs a specific task.
Parameters
Parameters are variables that are defined in the function definition.
Example:
def_godfathermovie (cinematic, suspenseful, violent).