All flashcards
Flashcard 1: Choose the correct way to start a multiline comment in Python.
Answer: Use triple quotes: '''comment'''. Triple quotes allow comments spanning multiple lines.
Flashcard 2: What is a string in programming?
Answer: A sequence of characters. Text data type enclosed in quotes or apostrophes.
Flashcard 3: Which keyword defines a function in Python?
Answer: 'def'. Keyword that declares new function definitions in Python.
Flashcard 4: What is the output of 'print("Hello, World!")'?
Answer: Hello, World. Print function displays text exactly as written inside quotes.
Flashcard 5: Identify the correct syntax for a Python function call.
Answer: function_name(arguments). Parentheses after name pass values to function parameters.
Flashcard 6: What does 'len()' function return?
Answer: The number of items in an object. Built-in function counts elements in sequences and collections.
Flashcard 7: What is a 'while' loop used for?
Answer: To repeat code while a condition is true. While loops continue until condition becomes false.
Flashcard 8: Identify the error: 'if x = 10:'
Answer: Use '==' for comparison, not '='. Assignment operator should be comparison operator for conditions.
Flashcard 9: What is the main difference between a list and a tuple?
Answer: Lists are mutable; tuples are immutable. Lists can be modified; tuples cannot be changed.
Flashcard 10: Which data type is used for true/false values?
Answer: Boolean. Boolean data type represents logical values: True or False.
Flashcard 11: What is the purpose of a function in programming?
Answer: To encapsulate code for reuse and organization. Functions group code into reusable blocks with optional parameters.
Flashcard 12: What does the 'return' statement do in a function?
Answer: It exits the function and optionally returns a value. Return sends a value back to the caller and stops execution.
Flashcard 13: Identify the error in the expression: 5+′3′
Answer: Type error: mixing integer and string. Cannot add integer and string directly without type conversion.
Flashcard 14: Choose the correct syntax to declare an integer variable in Python.
Answer: variable_name = 0. Python uses assignment operator to create variables dynamically.
Flashcard 15: Which operator is used for exponentiation in Python?
Answer: '**'. Double asterisk performs mathematical power operations.
Flashcard 16: Which data structure uses key-value pairs?
Answer: Dictionary. Dictionaries map unique keys to corresponding values.
Flashcard 17: What is the result of 3//2 in Python?
Answer:
- Floor division operator returns integer quotient without remainder.
Flashcard 18: What is the purpose of the 'if' statement in programming?
Answer: To execute code conditionally based on a boolean expression. It evaluates the boolean and runs code only when true.
Flashcard 19: What does the 'append' method do to a list?
Answer: Adds an element to the end of the list. Append method inserts new item at list's final position.
Flashcard 20: Identify the error in this function definition: 'def add(a, b): return a + b'
Answer: No error; the function is correct. This function definition follows proper Python syntax rules.
Flashcard 21: What is an array?
Answer: A collection of elements identified by index. Arrays store multiple values accessible by numeric position.
Flashcard 22: What is the purpose of a 'for' loop?
Answer: To iterate over a sequence of items. For loops process each item in collections automatically.
Flashcard 23: How is a comment started in Python?
Answer: Using '#'. Hash symbol creates single-line comments in Python code.
Flashcard 24: Identify the component of a loop that determines when it stops.
Answer: Loop condition or termination condition. This boolean expression controls when the loop continues or stops.
Flashcard 25: Identify the error in this loop: 'for i in range(5) print(i)'
Answer: Missing colon after range(5). Python requires colon after for statement header.
Flashcard 26: Which keyword is used to start a loop in Python?
Answer: 'for' or 'while'. Both keywords create repetitive execution structures in Python.
Flashcard 27: What is the result of 4×(3+2)?
Answer:
- Order of operations: parentheses first, then multiplication.
Flashcard 28: Which data structure uses key-value pairs?
Answer: Dictionary. Dictionaries map unique keys to corresponding values.
Flashcard 29: Identify the error in 'for i in 5: print(i)'
Answer: 'range()' is needed to iterate through integers. Cannot iterate directly over integer; range creates sequence.
Flashcard 30: What is an 'else' clause used for?
Answer: To execute code when an 'if' condition is false. Else provides alternative code path for false conditions.