Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the annotation methods of python

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the annotation methods of python". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the annotation methods of python".

Common comments-use # single-line comments

This annotation method is quite common, similar to / / in the Java language. Python uses # for single-line comments, and peer content after # will not be executed by the interpreter.

# pound sign at the beginning of the line, all contents of the line will not be executed print ("hello W3Cschool") # # pound sign after the code, the code before the pound sign will not be executed, the code after the pound sign will not be executed # if the content after the pound sign appears # will not end the comment effect

Multiline comments-informal annotation method

This annotation method is similar to / * / in java, where python uses three single quotation marks or three double quotation marks to annotate, and content surrounded by three quotation marks will not be executed by the interpreter (doubtless, it should be executed by the interpreter, but has no effect).

Print ('this is an output') "" three double quotes can be commented across multiple lines print ('inline code is not interpreted') "print (" this is another output ")" three single quotes have the same effect as three double quotes' print ("the print function uses three quotes in order to explain the irregularity of this annotation method You will find that the print function has changed a lot of lines, but it can still be executed. In fact, triple quotation mark enclosing is a special string expression. The principle of taking this comment is just to create a string and then not assign a value. The following line of code is the assignment "") str = 'this is a string of string stone hammers' 'print (str). "

Because python code uses indentation to distinguish code blocks instead of semicolons, python code is clear and organized to read. It is also very convenient to comment when commenting. Therefore, the editor does not recommend using this method for multiline comments.

Quick annotation method

Shortcuts to comments vary in different IDE or code editors, but you can use Ctrl + / for code comments in both VSCode and pycharm

Select multiple lines to comment on multiple lines.

Thank you for your reading, these are the contents of "what are the annotation methods of python". After the study of this article, I believe you have a deeper understanding of what the annotation methods of python have, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report