Skip to content

Latest commit

 

History

History
149 lines (118 loc) · 2.08 KB

File metadata and controls

149 lines (118 loc) · 2.08 KB

Lecture-3 Format Function, Arithmetic Operators in Python

End Variable In python

print("Good Evening",end="\n")
print("Hello Everyone")
print("Good Evening",end=" ")
print("Hello Everyone")

What is the format () function in Python?

The Python format () function formats strings according to the position.

Example=

x="Vedika"
y=21
dob= "01/01/2001"
print("Hello {} .Your Age is {} .Your DOB is {}". format(x,y,dob))
x="Vedika"
y=21
dob= "01/01/2001"
print("Hello {place1} .Your Age is {place2} .Your DOB is {place3}". format(place3=dob,place2=y,place1=x))

Types of operators in Python


Arithmetic Operators=

  1. Addition Operator (+)
a=10
b=20
c=a+b
print(c)
  1. Subtraction Operator (-)
a=10
b=20
c=a-b
print(c)
  1. Multiplication Operator (*)
a=10
b=20
c=a*b
print(c)
  1. Division Operator (/)
a=10
b=20
c=a/b
print(c)
  1. Modulus Operator (%)
a=10
b=20
c=a%b
print(c)
  1. Exponentiation Operator (**)
a=10
b=20
c=a**b
print(c)
  1. Floor Operator (//)
a=10
b=20
c=a//b
print(c)

🏠 HomeWork

1️⃣Write a program to print student information and use format function to inject variable.

👁 Show Answer

a= "vedika"
b=19
c=2003
d=55

print("Hello {} .your Age is {} .your DOB is {}. and your Roll Number is {}".format(a, b, c, d))

2️⃣Write a program to implement an arithmetic operators.

👁 Show Answer

a=113
b=11
print("Addition(±)        :-",a+b)
print("Subtraction(-)     :-",a-b)
print("Mulitiplication(*) :-",a*b)
print("Division(\)        :-",a/b)
print('modules(**)        :-',a**b) 
print('Exponential(%)     :-',a%b)
print('Floor Division(//) :-',a//b)

🔗 Some Useful Links

📖 References