python学习笔记(2)

来源:互联网 发布:洛阳市博物馆 知乎 编辑:程序博客网 时间:2024/05/22 14:21

Python中变量命名规则:

1、区分大小写

2、变量名必须以字母或下划线字符开头

3、变量名中不能包含空格

 

字符显示:

单引号与双引号在字符串标识中效果一致

Python中“+”可以作为运算符号,也可以作为字符串拼接符号。

如果要显示多行的字符串要使用三重引号如下:

long_string = """Down by the Salley Gardens 走进莎莉花园

My love and I did meet 我和我的爱人相遇

She passed the Salley Gardens 她穿越莎莉花园

With little snow-white feet 踏著雪白的纤足

She bid me take love easy 她请我轻柔的对待这份情

As the leaves grow on the tree 像依偎在树上的群叶"""

print(long_string)

运行结果:

若是使用一个引号

long_string = "Down by the Salley Gardens 走进莎莉花园

My love and I did meet 我和我的爱人相遇

She passed the Salley Gardens 她穿越莎莉花园

With little snow-white feet 踏著雪白的纤足

She bid me take love easy 她请我轻柔的对待这份情

As the leaves grow on the tree 像依偎在树上的群叶"

print(long_string)

 

运行提示:long_string = "Down by the Salley Gardens走进莎莉花园

                                                    ^

SyntaxError: EOL while scanning string literal在字符串首尾忘记加引号

0 0