发布时间:2019-08-01 17:12:52编辑:auto阅读(1509)
# Auther: Aaron Fan
#字符转格式化:
name = input("Enter your name: ")
age = int(input("Enter your age: "))
job = input("Enter your job: ")
#方法1(最推荐的方法)
info2 = '''
---------- The %s info ----------
Name is %s.
Age is %d.
Job is %s
''' % (name,name,age,job)
print(info2)
#方法2(知道有这个东西就行了)
info2 = "---------- The %s info ----------"
info2 += "\nName is " + name
info2 += "\nAge is " + str(age)
info2 += "\nJob is " + job
print(info2)
#方法3(这种写法必须按顺序来,知道有这个东西就行了)
info2 = '''
---------- The {0} info ----------
Name is {1}
Age is {2}
Job is {3}
''' .format(name,name,age,job)
#day2中的str字符串操作中有介绍另一种format的用法,可以不用按照顺序去写
print(info2)
上一篇: python之commands模块
下一篇: python学习笔记-3运算符与表达式
47491
45793
36791
34322
28959
25596
24442
19609
19110
17631
5464°
6047°
5569°
5637°
6572°
5375°
5377°
5883°
5854°
7169°