1/170
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is the main function of an interpreter in Python?
An interpreter runs your code, translating and executing it line by line.
What happens if there is an error in the code while using an interpreter?
The interpreter stops execution at the point of the error.
What is a key advantage of using an interpreter?
Easier debugging and no separate compile step.
What is a disadvantage of using an interpreter?
Slower execution overall compared to compiled languages.
What does a compiler do?
A compiler translates the entire program into machine code before execution.
What is a key advantage of using a compiler?
Faster execution and optimized code.
What is a disadvantage of using a compiler?
Slower to test since the code must be compiled first.
Define 'Lexis' in programming languages.
Lexis refers to the 'words' or tokens of the language, such as keywords and identifiers.
What is the role of syntax in programming?
Syntax defines the rules for how code must be written, similar to grammar in English.
What error occurs if syntax rules are broken in Python?
A SyntaxError is raised.
What does semantics refer to in programming?
Semantics is the meaning of the code and what it does.
What type of error occurs if the meaning of the code is incorrect?
A semantic (logic) issue may cause a TypeError or incorrect output.
What are keywords in Python?
Keywords are reserved words with special meaning that cannot be used as variable names.
Give an example of a Python keyword.
Examples include 'if', 'else', 'while', 'def', 'True', 'False'.
What is an instruction in Python?
An instruction is a single command that Python executes.
What is the purpose of indentation in Python?
Indentation defines code blocks and is required for proper structure.
What happens if indentation is incorrect in Python?
An IndentationError is raised.
What are comments in Python?
Comments are notes in your code that Python ignores, helping humans understand the code.
What is the syntax for a single-line comment in Python?
A single-line comment starts with a '#' symbol.
What is a multi-line comment in Python?
A multi-line comment is enclosed in triple quotes ("""...""").
Why are comments important in programming?
They explain logic, make code readable, and assist with debugging and collaboration.
What is the Boolean data type in Python?
A data type that represents truth values, either True or False.
How are integers defined in Python?
Integers (int) are whole numbers without decimals, e.g., x = 10, y = -3.
What is a floating-point number in Python?
A float is a number that includes decimals, e.g., pi = 3.14, temp = -5.5.
What is scientific notation used for in Python?
It is used for very large or very small numbers, e.g., a = 1e3 (1000.0).
What is a string in Python?
A string (str) is text enclosed in quotes, e.g., name = 'Amber'.
What numeral systems does Python support?
Python supports decimal (base 10), binary (base 2), octal (base 8), and hexadecimal (base 16).
What is the prefix for binary numbers in Python?
The prefix for binary numbers is '0b', e.g., 0b1010.
What is the prefix for octal numbers in Python?
The prefix for octal numbers is '0o', e.g., 0o12.
What is the prefix for hexadecimal numbers in Python?
The prefix for hexadecimal numbers is '0x', e.g., 0xA.
What is a variable in Python?
A variable is a named container for data, e.g., age = 17.
What are the rules for naming variables in Python?
Variable names must start with a letter or underscore, and cannot use keywords or start with a number.
What is PEP 8 in Python?
PEP 8 is the official style guide for writing clean Python code.
What is the purpose of snake_case in variable naming?
Snake_case is used to improve readability in variable names, e.g., user_name.
What is the result of the expression '10 / 3' in Python?
The result is a float: 3.3333...
What does the '//' operator do in Python?
The '//' operator performs floor division, returning the largest whole number less than or equal to the result.
What are the two types of operators based on the number of operands?
Unary operators (one operand) and binary operators (two operands).
What is the order of operations in Python?
Python follows the order similar to PEMDAS: Parentheses, Exponents, Multiplication/Division, Addition/Subtraction.
What does the '&' operator do in Python?
The '&' operator performs a bitwise AND operation.
What does the '|' operator do in Python?
The '|' operator performs a bitwise OR operation.
What does the '^' operator do in Python?
The '^' operator performs a bitwise XOR operation.
What does the '~' operator do in Python?
The '~' operator performs a bitwise NOT operation.
What does the '<<' operator do in Python?
The '<<' operator shifts bits to the left.
What does the '>>' operator do in Python?
The '>>' operator shifts bits to the right.
What is the output of `print(not True)`?
False
What does the `and` operator require for the result to be True?
Both conditions must be True.
What does the `or` operator require for the result to be True?
At least one condition must be True.
What is a Boolean expression?
An expression that evaluates to True or False.
What is the output of `print(5 > 3)`?
True
What is the output of `print(10 == 7)`?
False
What do relational operators do?
They compare values.
What is the output of `print(5 != 3)`?
True
What is the output of `print(2 < 4)`?
True
What is the output of `print(2 <= 1)`?
False
What is a common issue with floating-point numbers in Python?
They are not perfectly precise.
What is the result of `print(0.1 + 0.2 == 0.3)`?
False (due to floating-point precision errors)
What is type casting?
Converting between data types.
How do you convert a string to an integer in Python?
Using `int()`, e.g., `x = int('5')`.
What does the `input()` function do?
It gets data from the user.
What does `input()` always return?
A string.
What is the purpose of the `sep` parameter in the `print()` function?
It controls what goes between multiple values.
What does the `end` parameter in the `print()` function control?
What is printed at the end of the output.
What is the syntax for an if statement in Python?
if condition: code to execute
What does an if-else statement provide?
Two possible paths of execution.
What is the purpose of the `elif` statement?
To check multiple conditions in order.
What does an if-elif-else statement handle?
All possible cases.
What is nesting in conditional statements?
Putting an if statement inside another if statement.
What is the common mistake when using comparison operators?
Using `=` instead of `==`.
What is the purpose of the `pass` statement?
It acts as a placeholder that does nothing.
What happens if you do not indent your code properly in Python?
It will result in an indentation error.
What is the output of `print(5 + 3)`?
8
What does the `float()` function do?
Converts a string to a floating-point number.
What is the purpose of a while loop?
To repeat a block of code while a condition is True.
What will the following code output? `x = 1 while x <= 3: print(x); x += 1`
1 2 3
What is an infinite loop?
A loop that runs forever unless stopped, e.g., `while True: print('Forever')`.
What is the purpose of a for loop?
To iterate over a sequence or a range a fixed number of times.
What does `for i in range(3): print(i)` output?
0 1 2
What does `range(5)` generate?
0, 1, 2, 3, 4
What is the output of `for letter in 'Hi': print(letter)`?
H i
What does the else block do in a for loop?
It runs if the loop finishes normally without hitting a break.
What happens when you use `break` in a loop?
It stops the loop completely.
What does `continue` do in a loop?
It skips the current iteration and continues with the next one.
What is the output of `for i in range(5): if i == 3: break; print(i)`?
0 1 2
What is the output of `for i in range(5): if i == 3: continue; print(i)`?
0 1 2 4
What is a list in Python?
A collection of values that can store different data types.
How do you access the first element of a list `nums = [10, 20, 30]`?
Using indexing: `nums[0]`.
What does slicing a list `nums[1:3]` return?
Elements from index 1 to 2, excluding 3.
What is the function of `len()`?
It returns the number of elements in a list.
What does `nums.append(4)` do?
Adds the value 4 to the end of the list nums.
What is the difference between `list.sort()` and `sorted(list)`?
`list.sort()` sorts the list in place, while `sorted(list)` returns a new sorted list.
What is a tuple in Python?
An ordered collection of values that is immutable (cannot be changed).
How do you create a single-element tuple?
By including a comma, e.g., `(5,)`.
What happens if you try to modify a tuple?
It raises an error because tuples are immutable.
What is a dictionary in Python?
A collection of key-value pairs, defined using curly braces.
What must dictionary keys be?
Unique and immutable (e.g., strings, numbers, tuples).
What is the output of `empty = {}; person = {'name': 'Alex', 'age': 18}`?
An empty dictionary and a dictionary with two key-value pairs.
What is the difference between a list and a tuple?
A list is mutable (can change), while a tuple is immutable (cannot change).
What does `del` do in the context of lists?
It deletes elements or entire lists.
What is the significance of nesting lists or tuples?
You can create complex data structures like matrices (2D lists) or cubes (3D lists).
How do you access a value in a dictionary?
Using the syntax dict[key].