#的英文:pound character或者octothorpe

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

 #!/usr/bin/python
#coding:utf-8 #编码方式 #打印一行* print "********************" #我也是注释 """
我是多行注释
""" print "您是不是没看到 我是多行注释的说明"

结果:

特别说明下:

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

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

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

 Python will default to ASCII as standard encoding if no other encoding hints are given.

 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:

 # coding=<encoding name>
or (using formats recognized by popular editors): #!/usr/bin/python
# -*- coding: <encoding name> -*-
or: #!/usr/bin/python
# vim: set fileencoding=<encoding name> :
More precisely, the first or second line must match the following regular expression: ^[ \t\v]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)
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. 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). 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.

最新文章

  1. linux grep
  2. 在Windows上将ReactNative集成到现有的Android项目
  3. Linux之Shell脚本计算命令行的所有和
  4. 【转】变量的声明和定义,从C到编译原理到C++,再到Java
  5. Windows7(x64)下Oracle10g安装
  6. Vue.js相关知识2-组件
  7. androisd wifi
  8. C# zip/unzip with ICSharpCode.SharpZipLib
  9. Android自定义Activity酷炫的动画跳转效果
  10. 《大数据互联网大规模数据挖掘与分布式处理》阅读笔记(四)-----WEB广告
  11. 模拟摇奖:从1-36中随机抽出8个不重复的数字(math)
  12. tmux 终端复用详解
  13. PHP MySQL Update
  14. 浅谈基于Linux的Redis环境搭建
  15. less is more,so 只记 less
  16. [转] getBoundingClientRect判断元素是否可见
  17. Python内置常量
  18. Math对象的常用属性和方法
  19. Oracle 12c利用数据泵DataPump进行Oracle数据库备份
  20. redis作为mysql的缓存服务器(读写分离)

热门文章

  1. docker~windows版本的安装与使用
  2. 基于Entity Framework的自定义分页,增删改的通用实现
  3. bzoj2120: 数颜色 [莫队][分块]
  4. Ansible 运维自动化 ( 配置管理工具 )
  5. Nginx文档-初学者指南
  6. 初学安卓开发随笔之 Intent 用法
  7. Framework7 索引列表插件的问题
  8. Hibernate的事务处理机制和flush方法的用法
  9. Nginx配置抵御DDOS或CC攻击
  10. Datatables快速入门开发--一款好用的JQuery表格插件