博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python--注释
阅读量:4678 次
发布时间:2019-06-09

本文共 1810 字,大约阅读时间需要 6 分钟。

#的英文:pound character或者octothorpe 

python中单行注释用#,多行注释用""",看下面的代码:

1 #!/usr/bin/python 2 #coding:utf-8  3  4   5 #编码方式 6  7 #打印一行* 8  9 print "********************" #我也是注释10 11 """12 我是多行注释13 """14 15 print "您是不是没看到   我是多行注释的说明"

结果:

特别说明下:

为什么#coding:utf-8能起作用?

我们参考python的官方文档发现,这是规定好的,一共三种方式,第三种方式运用了正则表达式,有兴趣可以去研究下。网址:

这个PEP的目的是介绍在一个Python源文件中如何声明编码的语法。随后Python解释器会在解释文件的时候用到这些编码信息。最显著的是源文件中对Unicode的解释,使得在一个能识别Unicode的编辑器中使用如FUT-8编码成为可能

1 Python will default to ASCII as standard encoding if no other encoding hints are given. 2  3 To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as: 4  5 # coding=
6 or (using formats recognized by popular editors): 7 8 #!/usr/bin/python 9 # -*- coding:
-*-10 or:11 12 #!/usr/bin/python13 # vim: set fileencoding=
:14 More precisely, the first or second line must match the following regular expression:15 16 ^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)17 The first group of this expression is then interpreted as encoding name. If the encoding is unknown to Python, an error is raised during compilation. There must not be any Python statement on the line that contains the encoding declaration. If the first line matches the second line is ignored.18 19 To aid with platforms such as Windows, which add Unicode BOM marks to the beginning of Unicode files, the UTF-8 signature \xef\xbb\xbf will be interpreted as 'utf-8' encoding as well (even if no magic encoding comment is given).20 21 If a source file uses both the UTF-8 BOM mark signature and a magic encoding comment, the only allowed encoding for the comment is 'utf-8'. Any other encoding will cause an error.

 

转载于:https://www.cnblogs.com/feifei-cyj/p/7436627.html

你可能感兴趣的文章
【JBPM4】判断节点decision 方法3 handler
查看>>
filter 过滤器(监听)
查看>>
Linux进程间通信---共享内存
查看>>
Computer Information
查看>>
交换机/路由器上的 S口 F口 E口
查看>>
P1298(矩阵切割)DP
查看>>
wzplayer for delphi demo截图
查看>>
团队第二周:SRS文档
查看>>
Zookeeper的安装与使用:
查看>>
密码策略限制最大与最小长度
查看>>
正则表达式模式
查看>>
使用iframe实现同域跨站提交数据
查看>>
Mouse点击之后,复制GridView控件的数据行
查看>>
ASP.NET开发,从二层至三层,至面向对象 (2)
查看>>
如何查看自己电脑支持OpenGL core版本
查看>>
页面元素定位 XPath 简介
查看>>
[转]loadrunner:系统的平均并发用户数和并发数峰值如何估算
查看>>
Linux下Tomcat重新启动
查看>>
HTML Table to Json
查看>>
Theano 学习笔记(一)
查看>>