Easy Python programming questions for those just starting to code!
1. What is the result of 10 % 3 in Python?
💡 The % operator gives the remainder of division. 10 ÷ 3 = 3 remainder 1. So 10 % 3 = 1.
2. Which keyword starts a conditional statement in Python?
💡 Python uses "if" to start a conditional statement: if condition: do something.
3. What is the Python keyword to exit a loop early?
💡 The "break" keyword terminates a loop immediately when executed.
4. How do you start a for loop in Python to repeat 5 times?
💡 range(5) generates numbers 0-4. "for i in range(5):" loops exactly 5 times.
5. Which of these is a valid Python string?
💡 Strings in Python are enclosed in single or double quotes: "Hello" or 'Hello'.
6. What is the correct way to print "Hello" in Python?
💡 Python uses the print() function to display output: print("Hello")
7. What does len("Python") return?
💡 len() returns the number of characters in a string. "Python" has 6 characters.
8. How do you create a variable named "age" with value 25 in Python?
💡 In Python, variables are created by simply assigning a value: age = 25. No type declaration needed.
9. What does type(42) return in Python?
💡 type(42) returns <class "int"> because 42 is an integer in Python.
10. Which keyword is used to define a function in Python?
💡 In Python, the "def" keyword is used to define a function: def my_function():