What Python function is used to display text on the screen?
print()
What character is used to create a new line in a string?
\n
What operator is used for exponentiation (powers)?
**
What loop is used to repeat something a certain number of times?
for loop
What module lets you generate random numbers in Python?
random
What function lets the user type something into the program?
input()
What does this print: print("Python\tRocks")?
It prints with a tab between words: Python Rocks
What is the result of 5 // 2?
2 (integer division)
What loop runs while a condition is true?
while loop
What function gives a random number between 1 and 10 (inclusive)?
random.randint(1, 10)
How do you print a string with a quote inside it, like: He said "hello"?
Use escape character: print("He said \"hello\"")
How can you insert a variable into a string using f-strings?
Use f"Hello {name}"
What operator checks if two values are equal?
==
What keyword is used to stop a loop early?
break
What statement is used to handle exceptions in Python?
try and except
What symbol is used to combine strings in a print statement?
The + operator (concatenation)
What method turns a string to uppercase?
.upper()
What does != mean?
Not equal to
What keyword skips the rest of the loop and goes to the next iteration?
continue
How do you open a file for reading using with?
with open("filename.txt", "r") as f:
What does the end parameter in print() do?
It changes what is printed at the end (default is a newline)
What method removes whitespace from the beginning and end of a string?
.strip()
What is the result of True and False?
False
What keyword do you use to check a condition after an if?
elif
What keyword is used to include code from another Python file?
import