python 注释含注释_Python注释

python 注释含注释

Python注释 (Python comments)

Comments in Python are used to improve the readability of the code. It is useful information given by the programmer in source code for a better understanding of code and logic that they have used to solve the given problem to the reader. Comments are not executed during the compilation and also not show on the output.

Python中的注释用于提高代码的可读性。 程序员在源代码中提供的有用信息有助于更好地理解他们用来解决给读者的问题的代码和逻辑。 注释不会在编译期间执行,也不会显示在输出中。

In Python, comments are done by using the hash (#) and delimiters ("" or ''') symbol with no whitespace between starting. Now we will try to learn the types of comments with some examples.

在Python中, 注释是通过使用井号( # )和定界符( “”或''' )符号完成的,开始之间没有空格。 现在,我们将尝试通过一些示例来学习评论类型

Python中的注释类型 (Types of comments in Python)

There are two types of comments in Python,

Python有两种类型的注释

  1. Single line comment (#)

    单行注释(#)

  2. Multi-line string as comment (''')

    多行字符串作为注释(''')

1)单行注释 (1) Single line comments)

In Python, single-line comments are used for comments one-line statements like explanations of different variables, functions, expressions, etc. To do single-line comments a hash (#) symbol is used with no whitespace when the comments go to the next line then must put one another hashtag(#) at the start of the next line. Let's see an example and try to understand how we apply the single-line comments in the program.

在Python中, 单行注释用于注释单行语句,例如对不同变量,函数,表达式等的解释。要进行单行注释,当注释转到末尾时,将使用无空格的井号( # )符号下一行然后必须在下一行的开头放置另一个hashtag(#)。 让我们看一个示例,尝试了解我们如何在程序中应用单行注释。

Example:

例:

# Single line comments example
# a program to print a given string and addition.

print('Welcome @ IncludeHelp')
a=2
b=5
print(a+b)

# addition of both numbers by using plus(+) sign.

Output

输出量

Welcome @ IncludeHelp
7

2)多行字符串注释 (2) Multi-line string comments)

As we have seen in the above example that single-line comments, for multi-line we have to put a hash (#) symbol in each line. In Python, To overcome this problem multi-line string comments using delimiter (''') are provided. It is useful when does not fit in one line. For multiline string comments, we have to enclose the string with delimiter at both ends.

正如我们在上面的示例中看到的那样,对于多行单行注释必须在每行中添加一个井号( # )。 在Python中,为了解决此问题,提供了使用定界符( ''' )的多行字符串注释。 当不能排成一行时很有用。 对于多行字符串注释,我们必须在两端用定界符将其括起来。

Note: A delimiter is a sequence of one or more characters.

注意:分隔符是一个或多个字符的序列。

Example:

例:

'''
    Here we will check a given number n is even or odd 
    with multi-line comments in Python.
'''

n=6768

if n%2==0:
       print("Even number.")
else:
      print("Odd number.")

Output

输出量

Even number.


翻译自: https://www.includehelp.com/python/comments.aspx

python 注释含注释

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值