Python Essentials Flashcards

1
Q

What are the six primitive values and types?

A

int, float, complex, bool, str, and NoneType

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

What is the int type? Give an example.

A

Integers (whole numbers). Example: x = 1

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

What is the float type? Give an example.

A

Floating-point numbers (decimals). Example: x = 1.0

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

What is the complex type? Give an example.

A

Numbers with real and imaginary parts. Example: x = 1 + 2j

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

What is the bool type? Give an example.

A

Boolean (True/False values). Example: x = True

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

What is the str type? Give an example.

A

Strings (characters/text). Example: x = ‘hello’

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

What is the NoneType type? Give an example.

A

Special object indicating nulls. Example: x = None

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

What do variables do? Give an example.

A

They name values. Example: greeting = ‘hey there’

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

What is floor division? Example: a // b

A

An operation for integers and floats that gives the quotient (removes fractional parts) of a and b in the example: a // b

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

Can you type an example of formatted I/O and formatted string literals?

A

print(‘{X} has type {T}’.format(X=x, T=type(x)))

print(f’{x} has type {type(x)}’)

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

What is a tuple?

A

A read-only (‘immutable’) fixed-length sequence of values

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

What is the immutable version of a set?

A

A frozen set! NOT a tuple.

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

Is it quicker to access a mutable or an immutable object?

A

Immutable

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

Does it ‘cost’ more compute to change a mutable object or immutable object?

A

Immutable, because it requires creating a copy

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

Can the values that print from a tuple change?

A

YES, because the binding is unchangeable but not that objects that they are bound to. For example, the tuple could contain the variable ‘x’ which can be modified.

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

Do values in lists need to be the same type?

A

No