Python
Basic Types & None
20 flashcards · answers and spaced-repetition review in the KnowCard app
You want to check whether a result is the "no value" sentinel. Why prefer if x is None: over if x == None:?
What is the type of None, and how many instances of it exist at runtime?
What does this print?
```
def greet(name):
print("hi", name)
result = greet("Sam")
print(result)
```
What does this print?
```
nums = [3, 1, 2]
result = nums.sort()
print(result)
```
Is `None` truthy or falsy, and what does this print?
```
x = None
if x:
print("yes")
else:
print("no")
```
In Python, every value is an object with a type. What is the idea behind type(x), and what does type(5) return?
What does this print, and why does `+` behave differently on each line?
```
print(1 + 2)
print("1" + "2")
```
Python operators fall into a few categories. Name the category each of these belongs to: +, <, and, is, in.
What does this print?
```
print(2 * 3 + 4)
print(2 * (3 + 4))
```
What does this print, and what general rule decides it?
```
print(10 - 4 - 3)
```
What does the chained comparison 1 < 2 < 3 evaluate to, and how does Python expand it?
Which operators support chaining like `a < b <= c`, and what does this print?
```
x = 5
print(1 < x == 5)
```
What does this print, and why isn't the result a plain `True`/`False`?
```
print(0 or "hello")
print("a" and "b")
```
What is the difference between is and in, given x = [1, 2, 3]?
Which binds tighter — a comparison like `==` or a logical `and`? What does this print?
```
print(True == False and False)
```
What does this print, and which precedence gotcha causes it?
```
print(not 1 == 1)
```
Of Python's built-in types, which are mutable? Sort these: list, tuple, dict, set, frozenset, str, bytes, bytearray, int.
Are an empty dict {}, an empty set set(), and an empty frozenset() truthy or falsy?
What does this print, and why?
a = True
if a or print("Lazy"):
print("Evaluation")
A user is prompted for their age. What does this print, or does it fail?
age = input("Age: ") # user types 30
print(age + 1)
Start learning today
Free to start — download the app or use it in your browser.
