格式化输出:

格式化输出%占位符 s,d
格式化输出,在格式化输出中,单纯的表示%需要用%%去表示。
如果你的字符串中,用了%s或者%d这种形式,name后面的%,认为是占位,如果需要用到%,需要些%%去表示,print(‘我叫%s,今年%s,学习进度2%%’)
如果字符串中没有用到占位,那么%还是你的%。print('游戏加载80%了')
name = input('请输入名字:')
age = input('请输入年龄:')
sex = input('请输入性别:')

msg = '我的名字是' + name + '我的年龄是' + age + '我的性别是' + sex
print(msg)

msg = '''
------------ info of Alex Li -----------
Name  : Alex Li
Age   : 22
job   : Teacher
Hobbie: girl
------------- end -----------------
'''
格式化输出  %占位符  %s字符串  %d 整数 
%s处理字符串  全能的  
%d处理数字  只能接收数字
name = input('请输入姓名:')
age = int(input('请输入年龄:'))
job = input('请输入工作:')
hobby=input('请输入爱好:')

msg = '''
------------ info of %s -----------
Name  : %s
Age   : %d
job   : %s
Hobbie: %s
------------- end -----------------
''' % (name, name, age, job, hobby)
print(msg)
View Code

相关文章:

猜你喜欢
  • 2022-01-22
  • 2021-05-25
  • 2022-01-08
  • 2021-08-07
  • 2021-05-20
  • 2021-11-18
  • 2022-01-01
相关资源
相似解决方案