如何理解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/

没有评论

发表回复

Python
如何创建Miniforge的虚拟化环境?

1 前言 一个问题,一篇文章,一出故事。 笔者昨天完成Miniforge的环境部署,今天需要测试Mi …

Python
如何安装Miniforge的软件包?

1 前言 一个问题,一篇文章,一出故事。 笔者昨天完成Miniforge的环境部署,今天需要测试批量 …

Python
如何安装部署Miniforge?

1 基础知识 1.1 软件的介绍 – Miniforge是一个存储库 – M …