Lecture 2 Flashcards

1
Q

What is a variable?

A

‘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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a boolean?

A
False = 0 
True = 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

integer + float = ?

A

float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

integer + boolean = ?

A

integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

integer + string = ?

A

error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What function do you use to determine what variable a certain function is?

A

type()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function do you use to determine the length of a list?

A

len()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between a ‘list’ and an ‘array’?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does % mean?

A

modulus

e.g. 14%10 = 4
18%6 = 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Can you add / subtract / multiply a list with a string/integer/boolean?

A

No, this throws an error. You have to parse it first.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

float + boolean = ?

A

float

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

float + string = ?

A

error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What value does len() start counting at?

A

len() starts at 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the length of the following list?

[“Elephant”, 520, 5.0, [“Hello”, “World”]]

A

4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you determine the code of the following list? What is the output

List_1 = [5, 6.0, “hallo”, [1], [5, 3, “2”]]

A

print(len(List_1))

> 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Save the words Bird, Dog, and Cat in that order to a list called Animals

A

Animals = [“Bird”, “Dog”, “Cat”]

17
Q

How do you access items in a list?

A

Through indices

18
Q

List_1 = [3, 6, “hi”, 7.5, [5.4], True]

How do you access the value 7.5?

A

print(List_1[3])

19
Q

List_1 = [3, 6, “hi”, 7.5, [5, “house”], True]

How do you access the value ‘house’?

A

print(List_1[4][1])

20
Q

How do you access the item at the end of a list?

A
print(List_1[len(List_1)-1])
OR
print(List_1[-1])
21
Q

List_1 = [3, 6, “hi”, 7.5, [5.4], True]

How do you change 7.5 to an 8?

A

You got to select the INDEX of the value you want to change and assign it a new value.

Example:
List_1 = [3, 6, "hi", 7.5, [5.4], True]
List_1[3] = 8
print(List_1)
> [3, 6, 'hi', 8, [5.4], True]
22
Q

What function do you use to add items to a list?

A

.append()

23
Q

What function do you use to add a list to a list?

A

.extend()

24
Q

Add the value 8 to the end of List_1

List_1 = [3, 6, “hi”, 7.5, [5.4], True]

A

List_1.append(8)
print(List_1)
> [3, 6, “hi”, 7.5, [5.4], True, 8]