码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习(四)格式化输出

时间:2019-01-15 10:42:36      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:core   输出   oem   coding   for   please   inf   aaa   format   

# 格式化输出
# % s  d

# name = input("please input your name : ")
# age = input("please input your age : ")
# job = input("please input your job : ")
# # msg = ‘我叫%s , 今年%s‘ %(name,age)
# # print(msg)
#
#
#
# # %%  两个%%是为了转义  %  否则直接写57% 会报格式错误
#
# msg1 = ‘‘‘-----------------info of %s
# name : %s
# age : %s
# job : %s
# score : 56%%  
# --------------------------end of poem
#
# ‘‘‘% (name,name,age,job)
# print(msg1)

# 另外一种格式化输出  format

s2 = "my name is {},this year is {},my hobby is {},i love {}".format(‘smith‘,‘2019‘,‘coding‘,‘coding‘)
print(s2)

s3 = "my name is {0},this year is {1},my hobby is {2},i love {1}".format(‘smith‘,‘2019‘,‘coding‘,‘coding‘)
print(s3)


s4 = "my name is {aaa},this year is {name},my hobby is {age},i love {age1}".format(name=‘smith‘,age=‘2019‘,age1=‘coding‘,aaa=‘coding‘)
print(s4)








Python学习(四)格式化输出

标签:core   输出   oem   coding   for   please   inf   aaa   format   

原文地址:https://www.cnblogs.com/rookieagle/p/10269860.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!