Lecture 2 Flashcards
What is a variable?
‘a store of value’. variables can be seen as nametags, as they refer to values. They are not the values the refer to though.
e.g. a = 5
in here, the variable ‘a’ refers to the value 5.
What is a boolean?
False = 0 True = 1
integer + float = ?
float
integer + boolean = ?
integer
integer + string = ?
error
What function do you use to determine what variable a certain function is?
type()
What function do you use to determine the length of a list?
len()
What is the difference between a ‘list’ and an ‘array’?
list = variable type that consists of other variables
–> you can mix variable types within a list
array = variable type that consists of type specific lists
What does % mean?
modulus
e.g. 14%10 = 4
18%6 = 0
Can you add / subtract / multiply a list with a string/integer/boolean?
No, this throws an error. You have to parse it first.
float + boolean = ?
float
float + string = ?
error
What value does len() start counting at?
len() starts at 1
What is the length of the following list?
[“Elephant”, 520, 5.0, [“Hello”, “World”]]
4
How do you determine the code of the following list? What is the output
List_1 = [5, 6.0, “hallo”, [1], [5, 3, “2”]]
print(len(List_1))
> 5