Python学习格式化输出

Posted rookieagle

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习格式化输出相关的知识,希望对你有一定的参考价值。

# 格式化输出
# % 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学习格式化输出的主要内容,如果未能解决你的问题,请参考以下文章

Python的学习之旅———格式化输出

python学习日记(格式化输出,初始编码,运算符)

python学习笔记(注释用户输入格式化输出)

Python 学习笔记 -- 字符串格式化输出

Python基础学习

python学习篇2 - while循环,格式化输出,运算符,初识编码