0% found this document useful (0 votes)
3 views3 pages

Python Operators Questions

The document contains a series of Python operator questions divided into three categories: Normal Questions, Precedence Questions, and Associative Rule Questions. Each question requires explanations and examples related to Python operators, their behaviors, and the effects of operator precedence and associativity. The questions cover various operators including arithmetic, bitwise, and logical operators.

Uploaded by

lonlified
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Python Operators Questions

The document contains a series of Python operator questions divided into three categories: Normal Questions, Precedence Questions, and Associative Rule Questions. Each question requires explanations and examples related to Python operators, their behaviors, and the effects of operator precedence and associativity. The questions cover various operators including arithmetic, bitwise, and logical operators.

Uploaded by

lonlified
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Operator Questions

Normal Questions (5)


- What is the difference between the `/` and `//` operators in Python? Give an example.

- Explain the behavior of the `%` operator in Python with both positive and negative
numbers.

- What will be the output of `print(5 | 3)` and `print(5 & 3)`? Explain how these bitwise
operations work.

- How does the `is` operator differ from the `==` operator in Python? Provide an example.

- What will be the output of `print(2 ** -3)`? Explain why.

Precedence Questions (10)


- Evaluate the following expression step by step:
```python
result = 10 + 3 * 2 ** 2
print(result)
```

- What will be the output of the following code? Explain the order of execution.
```python
print(10 - 4 + 2 * 3)
```

- Consider the following expression:


```python
print(20 / 5 * 2 + 3)
```
What is the output, and why?

- Compute the result of the expression:


```python
print(5 + 2 ** 3 * 3)
```
Explain how operator precedence affects the calculation.

- Predict and explain the output of:


```python
print(2 ** 3 ** 2)
```
- Evaluate the following and explain:
```python
print(4 * 2 // 3 + 5)
```

- What will be the output of the following expression?


```python
print(True and False or True)
```

- Explain how the following expression is evaluated:


```python
print(5 & 3 | 2)
```

- Evaluate the following and explain:


```python
print(6 + 3 > 8 and 2 < 5 or 4 == 4)
```

- Analyze the result of the following code:


```python
print(3 * (4 + 2) / 2)
```

Associative Rule Questions (5)


- Given the left-associative nature of the `-` operator, evaluate:
```python
print(10 - 5 - 2)
```
How would the result differ if the operation were right-associative?

- Explain why the following two expressions give different results:


```python
print(8 / 2 / 2)
print(8 / (2 / 2))
```

- Demonstrate how associativity affects the following bitwise operation:


```python
print(10 | 5 & 3)
```

- Given that exponentiation (`**`) is **right-associative**, evaluate:


```python
print(2 ** 3 ** 2)
```
Explain why it is not evaluated as `(2 ** 3) ** 2`.

- Compare the results of these two expressions and explain the difference:
```python
print((5 - 2) - 1)
print(5 - (2 - 1))
```

You might also like