Python
Writing & Running a Program
24 flashcards · answers and spaced-repetition review in the KnowCard app
What does this print?
```
print("a") # print("b")
print("c")
```
Is a triple-quoted string like """ ... """ on its own a real multi-line comment in Python?
What's the difference between a statement and an expression in Python?
What does this print?
```
x = True
if x: print("Hello World")
```
What does this print, and what's the trap?
```
x = False
if x: print("Hi"); print("Bye")
```
What does this print?
```
var = (
10
+
10
)
print(var)
```
Outside of brackets, how do you continue a single statement onto the next physical line, and what's the catch?
When you read a Python traceback's location, why might the line it points to not be where you actually made the mistake?
On Linux/macOS, what does the shebang line #!/usr/bin/env python do, and why is it preferred over #!/usr/bin/python?
What does this print?
```
if True:
print("hi")
```
In Python, how is a statement body (block) tied to its header like if x > 10:?
Why is mixing tabs and spaces for indentation in the same block dangerous, even when the code looks correctly aligned?
What does this print?
```
if attempt < secret
print("Too small")
```
When you run python program.py, does Python skip compilation and execute the source line by line (like a shell script)?
A Python developer expects program.pyc to be a standalone executable like a compiled C binary. Why is that wrong?
What does this evaluate to?
```
s = "Hello " \
"World"
print(s)
```
In the guessing game, why is attempt = int(input("Guess: ")) wrong without the int(...), given the loop while attempt != secret and integer secret?
Are Otto and otto the same variable in Python? Can an identifier start with a digit or contain accented letters like é?
Why does class = 5 raise a SyntaxError in Python?
Python byte code is portable across platforms. So why does an equivalent C program usually run faster?
Your code looks aligned in your editor but Python rejects it after you mixed tabs and spaces. What does Python 3 do with inconsistently mixed tabs and spaces?
When Python prints an error message, what do its three parts tell you?
A colleague's Python error output doesn't match the wording in your textbook, even for the same bug. What changed?
You put #!/usr/bin/env python at the top of prog.py, but ./prog.py still won't run on Linux. What's missing, and would this line even matter on Windows?
Start learning today
Free to start — download the app or use it in your browser.
