当前位置:网站首页> 2. # 代码注释
2. # 代码注释
2022-08-01 02:31:00 【安迪Python】
2. Python # 代码注释
1. 什么是代码注释
代码注释即对代码进行批注说明。
相当于给一个英文单词批注中文释义。
【温馨提示】注释是给程序员自己看的,不会被电脑执行。
【示例】
# 用print函数输出一个整数
print(520)
520
上述代码中的第1行是注释,用来解释第2行代码。
2. 注释语法
一行注释语句通常由4部分组成:
1.#
2.空格
3.注释内容
4.注释位置
【解析】

1.#
是注释符号,位于注释行的开头;
2.#后面有一个空格,空格是为了批注看起来更美观;
3.写入注释内容;
4.注释可以在代码的上一行,也可以在代码的末端。

3. 注释位置
1. 注释在代码的上一行
# 用print函数输出一个整数
# 注意括号要使用英文小括号
print(520)
【终端输出】
520
2. 注释在代码的末端
print(520) # 用print函数输出一个整数
【终端输出】
520
4. 课堂练习
自己动手用print( )函数输出今天的日期,并为其写一行批注。
边栏推荐
- Daily practice of LeetCode - Circular linked list question (interview four consecutive questions)
- OSD读取SAP CRM One Order应用日志的优化方式
- Solve the problem that when IDEA creates a new file by default, right-click, new, there is no XML file
- 初出茅庐的小李第113篇博客项目笔记之机智云智能浇花器实战(2)-基础Demo实现
- 解决安装MySQL后,Excel打开很慢的问题
- Modify Postman installation path
- RTL8762DK RTC (5)
- 树莓派 的 arm 版的 gcc 安装 和环境变量的配置
- 【元胞自动机】基于matlab界面聚合元胞自动机模拟【含Matlab源码 2004期】
- WebApi hits an Attribute to handle exceptions uniformly
猜你喜欢
ARM 交叉编译
HCIP (14)
HCIP(14)
Completely closed Chrome updated and in the top right corner of the tip
RTL8762DK WDG (six)
这个地图绘制工具太赞了,推荐~~
RTL8762DK uses DebugAnalyzer (four)
Introduction to machine learning how to?
Data Middle Office Construction (VII): Data Asset Management
Solve the problem that Excel opens very slowly after installing MySQL
随机推荐
When opening a MYSQL table, some can display editing, some do not, how to set.
STK8321 I2C (Shengjia-accelerometer) example
Fat interface in JQESAP system
Simple vim configuration
MYSQL logical architecture
Parse the bootargs from the device tree (dtb format data)
High dimensional Gaussian distribution basics
The fledgling Xiao Li's 113th blog project notes: Wisdom cloud smart flower watering device combat (2) - basic Demo implementation
leetcode: 1562. Find latest grouping of size M [simulation + endpoint record + range merge]
设备树的树形结构到底是怎样体现的?
机器学习应该如何入门?
Talking about hardware device computing storage and data interaction
sqlserver cannot connect remotely
VPGNet
RTL8762DK uses DebugAnalyzer (four)
HCIP(14)
Js replication
lua entry case combat 123DIY
大佬们,MySQL cdc source在增量过程中回收 replication slave 和 r
The fledgling Xiao Li's 112th blog project notes: Wisdom cloud intelligent flower watering device actual combat (1) - basic Demo implementation