Python代码注释 - Python零基础入门教程 喜欢ヅ旅行 2022-10-20 03:51 152阅读 0赞 目录 * 一.什么是代码注释 * 二.为什么写代码要注释 * 三.代码注释的方式 * 1.单行注释,使用英文符号 \# * 2.多行注释 * 方法一:英文状态下使用单引号 ””” * 方法二:英文状态下使用双引号 “” (和方法一有点类似) * 方法三:选中单行或者多行,使用快捷键 Ctrl+/ * 四.重点总结 * 五.猜你喜欢 > 零基础 Python 学习路线推荐 : [Python 学习目录][Python] >> [Python 基础入门][Python 1] 在 [Python hello world 开始][Python hello world] 中我们已经完成了第一个 [Python][Python 2] 程序,代码是有了,关键是好像好不知道写的啥玩意? ![442cc4611318b008d77fd77975341985.png][] ## 一.什么是代码注释 ## 代码注释就是给一段代码加上说明,表明这段代码的作用或者实现的功能,方便别人阅读代码。 ![2848fa3188907450d3447a040c906e6f.png][] 看看上面这个图,问题来了,那个女孩是谁?张三?李四?王五?除了上帝谁也不知道\*\*(上帝:我也不知道)\*\*!! 加上注释再来一遍:禽兽,放开小红,我小明愿意和她交换。大家就都明白了,**原来这个女孩叫小红,这个 Gay 叫小明**。 ## 二.为什么写代码要注释 ## \*\*IT 圈有一个梗:\*\*\*\*当我写这段代码的时候,只有上帝和我知道,现在,只有上帝知道。上帝说:这个锅我不背!\*\* ![9b4c1cb8a56a21094ad17baa1877d3ec.png][] **IT 圈有一句话:提交代码不写注释的人,小 JJ 就跟注释一样长。一个团队开发时候可能是多个人同时接管一个项目,注释都没有,谁知道你写的什么玩意?** ![758710618bd7932dec8b5c3800bd8b38.png][] ## 三.代码注释的方式 ## ### 1.单行注释,使用英文符号 ### # python注释代码 1 # python注释代码 2 # python注释代码 3 # python注释代码 4 ### 2.多行注释 ### #### 方法一:英文状态下使用单引号 ””” #### ''' python注释代码 1 python注释代码 2 python注释代码 3 python注释代码 4 ''' #### 方法二:英文状态下使用双引号 “” (和方法一有点类似) #### """ python注释代码 1 python注释代码 2 python注释代码 3 python注释代码 4 """ #### 方法三:选中单行或者多行,使用快捷键 Ctrl+/ #### # python注释代码 1 # python注释代码 2 # python注释代码 3 # python注释代码 4 **值得注意的是:被注释的代码,程序在执行的时候会直跳过**!如下面代码: # !usr/bin/env python # -*- coding:utf-8 _*- """ @Author:猿说编程 @Blog(个人博客地址): www.codersrc.com @File:helloworld.py @Time:2021/3/13 20:37 @Motto:不积跬步无以至千里,不积小流无以成江海,程序人生的精彩需要坚持不懈地积累! """ print("hello word") **代码虽多,实际上编译只执行了最后一行代码!被注释的代码,程序自动跳过!** ## 四.重点总结 ## \*\* 总体说来 python 编程中的注释一共两个作用:\*\* * **1.方便代码阅读** * **2.被注释的代码,程序不会执行** ## 五.猜你喜欢 ## 1. [Python 简介][Python 3] 2. [Python Pycharm Anacanda 区别][Python Pycharm Anacanda] 3. [Python2.x 和 Python3.x,如何选择?][Python2.x _ Python3.x] 4. [Python 配置环境][Python 4] 5. [Python Hello World 入门][Python Hello World] 未经允许不得转载:[猿说编程][Python 2] » [Python 代码注释][Python 5] [Python]: https://www.codersrc.com/python [Python 1]: https://www.codersrc.com/pythonsimple [Python hello world]: http://www.shuopython.com/archives/630 [Python 2]: https://www.codersrc.com [442cc4611318b008d77fd77975341985.png]: /images/20221020/05e0de4f71f041f4a6d82327b2514106.png [2848fa3188907450d3447a040c906e6f.png]: /images/20221020/dcfbed37dd824611ba32e048707d3e34.png [9b4c1cb8a56a21094ad17baa1877d3ec.png]: /images/20221020/3efec0406b024b7c89854f71f62a0def.png [758710618bd7932dec8b5c3800bd8b38.png]: /images/20221020/e6fbf0d06fd4407d8187d17676c80ef6.png [Python 3]: https://www.codersrc.com/archives/4273.html [Python Pycharm Anacanda]: https://www.codersrc.com/archives/4346.html [Python2.x _ Python3.x]: https://www.codersrc.com/archives/4470.html [Python 4]: https://www.codersrc.com/archives/4397.html [Python Hello World]: https://www.codersrc.com/archives/4410.html [Python 5]: https://www.codersrc.com/archives/4724.html
还没有评论,来说两句吧...