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]之类

posted @ 2020-01-02 13:10  Luacy_hua  阅读(93)  评论(0)    收藏  举报