0% found this document useful (0 votes)
18 views2 pages

Python Basics: Operators and Conditions

Uploaded by

unnatiagrawal999
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)
18 views2 pages

Python Basics: Operators and Conditions

Uploaded by

unnatiagrawal999
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

Python Practical File - Prince Kurrey

1. Arithmetic Operators

a = 10
b = 5
print("Sum:", a + b)
print("Difference:", a - b)
print("Product:", a * b)
print("Division:", a / b)

Output:
Sum: 15
Difference: 5
Product: 50
Division: 2.0

Explanation: Performs basic arithmetic operations.

2. Assignment Operators

x = 7
x += 3
x *= 2
print("Final x:", x)

Output:
Final x: 20

Explanation: Uses += and *= to update the value of x.

3. Comparison Operators

a = 10
b = 8
print("a > b:", a > b)
print("a == b:", a == b)

Output:
a > b: True
a == b: False

Explanation: Compares two values using > and ==.

4. Logical Operators

x = 6
y = 12
print(x > 5 and y < 20)
print(x < 5 or y > 15)
Python Practical File - Prince Kurrey

print(not(x > 10))

Output:
True
False
True

Explanation: Demonstrates logical AND, OR and NOT.

5. if Statement

num = 12
if num % 2 == 0:
print("Even number")

Output:
Even number

Explanation: Checks and prints if number is even.

You might also like