格式化输出

1.% :占位符

%s:字符串占位符;既可以接收字符串,也可以接受数值

%d:数值占位符;只能接受数值。

案例:

1)

  name = input("your name:")

  age = input("your age:")

  ads = input("your ads:")

  print("my name is %s,my age is %s,my ads is %s" % (name,age,ads))

2)

  info = '''

  ------------ info of %s -----------

  Name:%s                       

  sex:%s

  Age:%s

  Job:%s

  ------------- end -----------------       

  '''% ('sean','sean','male','18','Teacher')

  print(info)

3)

  print("my name is %s,my age %s"%("sean","18岁"))

4)

  name = '王家卫'

  age = 31

  adds = 'HK'

  print('Hello Everyone,my name is {},my age is {},my adds is {}'.format(name,age,adds))  

      # fromat前为英文状态下的句号,而非逗号,与%占位符不同 ,%则无需标点符号

 

  

 




posted @ 2020-07-14 22:00  sean_wang  阅读(122)  评论(0编辑  收藏  举报