Week - 3 Exploring Python Operators & Conditional Statements
Creator 3.7."\t' Exploring Python Operators Python offers a plethora of operators, each serving a specific purpose in programming.

Week - 3 Exploring Python Operators & Conditional Statements

" Python offers a plethora of operators & Conditional Statements, each serving a specific purpose in programming"\end").  Let's delve into the various types         

Exploring Python Operators

Use this article as a reference sheet for 3.4"python#').

1. Arithmetic Operators:

- These operators perform mathematical operations.

- Addition (+)

- Subtraction (-)

- Multiplication (*)

- Division (/)

- Modulus (%)

- Exponentiation (**)

- Floor Division (//)

2. Comparison Operators:

- Comparison operators are used to compare values.

- Equal to (==)

- Not equal to (!=)

- Greater than (>)

- Less than (<)

- Greater than or equal to (>=)

- Less than or equal to (<=)

3. Logical Operators:

- Logical operators combine conditional statements.

- Logical AND (and)

- Logical OR (or)

- Logical NOT (not )

2.9.0

4. Assignment Operators:

- Assignment operators assign values to variables.

- Assignment (=)

- Add and assign (+=)

- Subtract and assign (-=)

- Multiply and assign (*=)

- Divide and assign (/=)

- Modulus and assign (%=)

- Exponentiation and assign (**=)

- Floor Division and assign (//=)

5. Bitwise Operators:

- Bitwise operators perform bit-level operations on integers.

- Bitwise AND (&)

- Bitwise OR (|)

- Bitwise XOR (^)

- Bitwise NOT (~)

- Left Shift (<<)

- Right Shift (>>)

6. Membership Operators:

- Membership operators test whether a value is present in a sequence.

- in: Returns True if the specified value is present in the sequence.

- not in: Returns True if the specified value is not present in the sequence.

7. Identity Operators:

- Identity operators compare the memory locations of two objects.

- is: Returns True if both operands point to the same object.

- is not: Returns True if both operands do not point to the same object.

Created own "Pdf\end').

Conditional Statements

Conditional statements in Python allow you to execute different blocks of code based on the evaluation of a condition. Here's a list of conditional statements in Python:

1. If Statement:

The if statement is used to execute a block of code if a condition is true.

x = 10
if x > 0:
    print("x is positive")        

The if-else statement is used to execute one block of code if the condition is true and another block if it's false.

2. If-else Statement:

The if-else statement is used to execute one block of code if the condition is true and another block if it's false.

x = -5
if x > 0:
    print("x is positive")
else:
    print("x is non-positive")        

3. If-elif-else Statement:

The if-elif-else statement allows you to check multiple conditions and execute different blocks of code accordingly.

x = 0
if x > 0:
    print("x is positive")
elif x < 0:
    print("x is negative")
else:
    print("x is zero")        

4. Nested If Statement:

You can nest one if statement inside another to create more complex conditional logic.

x = 10
if x > 0:
    if x % 2 == 0:
        print("x is positive and even")
    else:
        print("x is positive and odd")
else:
    print("x is non-positive")        

5. Ternary Conditional Operator:

Python also supports a ternary conditional operator for concise conditional expressions.

x = 10
message = "even" if x % 2 == 0 else "odd"
print("x is", message)        

"Below Chart Show All in One"

1.32a


要查看或添加评论,请登录

Satender Kumar的更多文章

社区洞察

其他会员也浏览了