'''是 Python 中用来表示多行字符串的标记

[root@centos8 pythoncode]$python char_code.py
请输入您的姓名: lijun
请输入您的年龄: 25
请输入您的工作: programmer
请输入您的工资: 13000
Name: lijun Age: 25 Job: programmer Salary: 13000 You will be retired in 40 years
[root@centos8 pythoncode]$vim char_code.py
[root@centos8 pythoncode]$cat char_code.py
#!/usr/bn/python

Name=input("请输入您的姓名: ")
Age=int(input("请输入您的年龄: "))
Job=input("请输入您的工作: ")
Salary=float(input("请输入您的工资: "))
msg='''Name: %s Age: %s Job: %s Salary: %d You will be retired in %s years'''%(Name,Age,Job,Salary,65-Age)
print(msg)
[root@centos8 pythoncode]$

 

 

这个'''是 Python 中用来表示多行字符串的标记。在Python中,三个单引号(''')或者三个双引号(""")可以用来创建多行字符串,这在需要书写包含换行符的长字符串时非常有用。

例如,在你的代码中,msg 变量的赋值使用了多行字符串的方式,这样可以更清晰地书写包含换行的文本内容。

在 Python 中,一对连续的单引号或双引号都可以用来定义多行字符串,只要开头和结尾的标记相同即可。这种方式可以让我们很方便地书写包含换行的长字符串,而不用担心换行符带来的影响。

posted on 2023-11-24 17:29  jun_li123  阅读(74)  评论(0)    收藏  举报

导航