Python String format() Method

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

rno=101
name="Vishal Sharma"
age=34
salary=50000
str="Your Roll No {rn}  and Name {nm} and Age {ag} and Salary {sl}"
str=str.format(rn=rno,nm=name,ag=age,sl=salary)
print(str)

Program 2

rno=int(input("Enter Roll No"))
name=input("Enter Name")
age=int(input("Enter Age"))
salary=int(input("Enter Salary"))

str="Roll No={} , Name={}, Age={} , Salary={}"
str=str.format(rno,name,age,salary)
print(str)

Program 3

a=int(input("Enter First Number"))
b=int(input("Enter Second Number"))
c=a+b
str=" Addition of {0} and {1} is {2} "
str=str.format(a,b,c)
print(str)

 

You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

1 Response

  1. Bright Kwame Boadu says:

    I am really enjoying

Leave a Reply

Your email address will not be published. Required fields are marked *