Tuesday, November 5, 2019

format method in python

# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 07:28:23 2019
@author: Anil Durgam
"""

name="anil"
age=29
salary = 20000
print("{}'s age is {} and his salary is{}".format(name,age,salary))
print("{0}'s age is {1} and his salary is{2}".format(name,age,salary))
print("{x}'s age is {y} and his salary is{z}".format(x=name,y=age,z=salary))
print("{x}'s age is {y} and his salary is{z}".format(z=salary,x=name,y=age))

output:
anil's age is 29 and his salary is20000
anil's age is 29 and his salary is20000
anil's age is 29 and his salary is20000
anil's age is 29 and his salary is20000

No comments:

Post a Comment

python class topic video