Back to notes
How did the behavior of the division operator change from Python 2.x to Python 3.x?
Press to flip
In Python 2.x, the division operator `/` performed integer division, while in Python 3.x, it performs floating-point division.
What does the concatenation operator `+` do with strings in Python?
It joins two strings together.
What is the order of operations in Python (PEMDAS)?
Parentheses, Exponents, Multiplication and Division (same precedence), Addition and Subtraction (same precedence); evaluated from left to right.
Explain the use of the floor division operator `//` with an example.
The floor division operator `//` divides and then floors the result to the nearest integer. Example: `7 // 5` results in `1`.
How do you display the result of an arithmetic operation in a Python script?
Use the `print` function, e.g., `print(x + y)`.
What are operands in the context of Python operators?
Values to which the operators are applied.
What is a statement in Python?
A unit of code the Python interpreter can execute.
Define the modulus operator in Python and provide an example.
The modulus operator `%` yields the remainder when the first operand is divided by the second. Example: `7 % 3` results in `1`.
What is the result of `7 // 5` in Python?
The result is `1`.
Explain the output of the script `first.py` if its content is: ```python print(100) x = 5 y = 20 print(x + y) ```, when executed by `python3 first.py`.
The output will be `100` followed by `25`.
Differentiate between interactive mode and script mode in Python.
Interactive mode allows typing and executing statements directly in the Python interpreter, while script mode involves writing a sequence of statements in a file and executing the script.
What file extension is used for Python scripts?
The `.py` extension.
List the types of operators in Python.
Addition `+`, Subtraction `-`, Multiplication `*`, Division `/`, and Exponentiation `**`.
Provide an example of an assignment statement in Python.
`x = 5`
What is an expression in Python?
A combination of values, variables, and operators that computes a value.
Previous
Next