Python day1 .format使用
格式化字符串的三种方式:
1、‘’‘ ’‘’.%(-,-,-,arg**)
name = input('name:') wife= input("your's wife's name:") father = input("your'father's name:") mother= input("your' mother's name:") info='''info of %s name:%s wife:%s father:%s mother:%s '''%(name,name,wife,father,mother) print(info)
2、‘’.format()
# author: Hua
name = input('name:')
wife= input("your's wife's name:")
father = input("your'father's name:")
mother= input("your' mother's name:")
info='''info of %s
name:%s
wife:%s
father:%s
mother:%s
'''%(name,name,wife,father,mother)
info2='''info of {_name}
name:{_name}
wife:{_wife}
father:{_father}
mother:{_mother}
'''.format(_name=name,_wife=wife,_father=father,_mother=mother)
print(info2)
3、用的极少,也难判断,如[1]/[0]之类

浙公网安备 33010602011771号