0% found this document useful (0 votes)
4 views5 pages

My Python Lab Manual

The document provides examples of various Python operators, including arithmetic, relational, assignment, logical, bitwise, ternary, membership, and identity operators. It also includes programs for adding and multiplying complex numbers, as well as printing the multiplication table of a given number. Each section demonstrates the use of the operators with code snippets and outputs.

Uploaded by

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

My Python Lab Manual

The document provides examples of various Python operators, including arithmetic, relational, assignment, logical, bitwise, ternary, membership, and identity operators. It also includes programs for adding and multiplying complex numbers, as well as printing the multiplication table of a given number. Each section demonstrates the use of the operators with code snippets and outputs.

Uploaded by

lakshmi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ILO:4.

Demonstrate the following operators in python with examples

1)AirthmeticOperators

a = 10
b = 5

print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Exponentiation:", a ** b)

2)relational operators
a = 10

b=5

print("a =", a)

print("b =", b)

print("a == b :", a == b)

print("a != b :", a != b)

print("a > b :", a > b)

print("a < b :", a < b)

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

print("a <= b :", a <= b)

3)assignment operators
a = 10

print("Initial value of a:", a)

a += 5

print("After += :", a)

a -= 3
print("After -= :", a)

a *= 2

print("After *= :", a)

a /= 4

print("After /= :", a)

a //= 2

print("After //= :", a)

a %= 3

print("After %= :", a)

a **= 2

print("After **= :", a)

4)logical operators
a = 10
b = 5

print("a =", a)
print("b =", b)

# Logical AND
print("(a > 5) and (b < 10) :", (a > 5) and (b < 10))

# Logical OR
print("(a < 5) or (b < 10) :", (a < 5) or (b < 10))

# Logical NOT
print("not(a > b) :", not(a > b))

5)bitwise operator
a = 10

b=4

print("a =", a)

print("b =", b)
print("a & b :", a & b) # Bitwise AND

print("a | b :", a | b) # Bitwise OR

print("a ^ b :", a ^ b)

6)ternary operator
a = 10

b = 20

# Ternary operator

largest = a if a > b else b

print("a =", a)

print("b =", b)

print("Largest number is:", largest)

7) membership operator
list1 = [10, 20, 30, 40, 50]

print("List:", list1)

print("20 in list1:", 20 in list1)

print("25 in list1:", 25 in list1)

print("20 not in list1:", 20 not in list1)

print("25 not in list1:", 25 not in list1)

8)Identity operator
a = [10, 20, 30]
b=a

c = [10, 20, 30]

print("a is b:", a is b)

print("a is c:", a is c)

print("a is not c:", a is not c)

ILO: 5)Write a program to add and multiply complex numbers


a = 2 + 3j

b = 4 + 5j

# Addition of complex numbers

addition = a + b

# Multiplication of complex numbers

multiplication = a * b

print("First complex number:", a)

print("Second complex number:", b)

print("Addition:", addition)

print("Multiplication:", multiplication)

ILO:6)write a program to print multiplication table of a given number


num = int(input("Enter a number: "))

# Printing multiplication table


print("Multiplication table of", num)

for i in range(1, 11):

print(num, "x", i, "=", num * i)

You might also like