0% found this document useful (0 votes)
3 views1 page

Python Programming Important QA

The document outlines the various categories of operators in Python, including arithmetic, comparison, logical, bitwise, assignment, membership, and identity operators. It explains operator precedence and associativity with examples to illustrate how expressions are evaluated. The document emphasizes the importance of understanding these concepts for effective programming in Python.

Uploaded by

6390niraj
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 views1 page

Python Programming Important QA

The document outlines the various categories of operators in Python, including arithmetic, comparison, logical, bitwise, assignment, membership, and identity operators. It explains operator precedence and associativity with examples to illustrate how expressions are evaluated. The document emphasizes the importance of understanding these concepts for effective programming in Python.

Uploaded by

6390niraj
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/ 1

Python Programming - Important Questions with Answers

Q1: Explain the various categories of operators in Python.

Operators in Python are used to perform operations on variables and values. Categories include:

1. Arithmetic Operators: +, -, *, /, %, **, //

2. Comparison Operators: ==, !=, >, <, >=, <=

3. Logical Operators: and, or, not

4. Bitwise Operators: &, |, ^, ~, <<, >>

5. Assignment Operators: =, +=, -=, *=, etc.

6. Membership Operators: in, not in

7. Identity Operators: is, is not

Example:

a = 3, b = 5, c = 10

i) a & b < 2/5**2 + c^b

- Operator precedence is applied. First **, then /, ^, &, <, +.

ii) b >> a**2 >> b**2 ^ c**3

- Again, follow precedence: ** > >> > ^

Q2: What do you mean by operator precedence and associativity?

Operator precedence determines which operator is evaluated first in an expression.

Associativity determines the order in which operators of the same precedence are evaluated.

Example: a = 5 + 2 * 3

- Multiplication has higher precedence, so result is 5 + (2*3) = 11

- Example of associativity: a = 5 - 2 - 1 => (5 - 2) - 1 = 2

You might also like