Basic Data Structures Flashcards
What is a data type?
A category for values and every value belongs to exactly one data type.
How can you check the type of a variable or value?
Use the function type()
What is an integer?
A value that is a whole number
What is the operator for exponent?
**
What is the operator for modulus?
%
What is the operator for integer division?
//
What are the operators for addition, subtraction, multiplication and division?
+ - * /
How is data typing in Python?
Dynamic - variables can change types
What is None in Python?
The null value, a data type of the class NoneType different from empty string, zero or False
What is a use case for the modulus (%)?
Perform an action every nth time
E.g. every third session the system will require the user to login
for i in session_number:
if i % 3 == 0:
#require login
What is the order of operations in Python?
- exponentiation and root extraction
- multiplication and division
- addition and subtraction
How can you change the order of operations?
Use parentheses
How can you add a value to an existing variable?
Use the += operator
e.g. num = 5
num += 2
What happens when you try to divide by 0?
You get a ZeroDivisionError
What is a floating point?
A value with a decimal point
What type of data do you get when you divide 2 integers?
a float
What type of data do you get when you divide 2 integers using the // operator?
an integer
What is a string?
A series or list of characters.
Each character has an index, starting at 0.
Anything inside single (‘’) or double (“”) quotes