如何理解Python注解与字符串的关系?

Python

1 注解与字符串的关系

1.1 Python的注解与字符串

– Python使用“#”字符注释(注释从“#”开始延伸到物理行末)
– “#”字符后面的内容会被程序负略(不被执行)
– 注释字符“#”不能包含在字符串中,包含则被当做字符串处理

1.2 实操理解

# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # this is the first comment
... spam = 1 # and this is the second comment
>>>          # ... and now a third!
... text = "# This is not a comment because it's inside quotes."
>>> print spam
1
>>> print text
# This is not a comment because it's inside quotes.
>>> quit()

注:
– 程序第一至三行字符“#”后面的内容被负略
– 程序第三行由于字符“#”包含在双引号中,所以字符“#”被当做普通字符处理,没有起到注释的作用

参阅文档:
https://docs.python.org/2.7/tutorial/index.html
https://docs.python.org/2.7/

没有评论

发表回复

FTP & SFTP & FTPS
如何使用Python连接FTP?

1 前言 一个问题,一篇文章,一出故事。 笔者遇到一个需要使用Python连接ftp的需求,于是整理 …

Python
如何安装部署pysmb?

1 基础知识 pysmb是一个实验性的SMB/CIFS库 pysmb用Python编写 pysmb实 …

Python
如何安装部署Anaconda3?

1 基础知识 1.1 Anaconda的版本 – Anaconda Enterprise …