directory

  • What are code comments
  • Why comment code
  • Three. The way code comments
    • 1. Single-line comments using the English symbol #
    • 2. Multi-line comments
      • Method 1: Use single quotation marks in English
      • Method 2: Use double quotation marks in English (similar to method 1)
      • Method 3: Select one or more lines and press Ctrl+/
  • Four. Key summary
  • Five. Guess you like it

Recommended path for learning Python: Python Learning Directory >> Python Basics

In Python Hello World we have completed the first Python program. The code is there, but the key is not to know what to write.

What are code comments

Code comment is to add a description to a piece of code, indicating the function of the code or the implementation of the function, easy for others to read the code.

Look at the picture above, which begs the question, who is that girl? Zhang SAN? Li si? Cathy? Nobody but God knows ** (God: I don’t know) **!!

Add notes to come again: beast, let go of xiao Hong, I xiao Ming is willing to exchange with her. We all understand, the original girl called Xiao Hong, the Gay called Xiao Ming.

Why comment code

There’s a meme in IT circles that when I wrote this code, only God and I knew. Now, only God knows. God said: THIS pot I do not carry!

There is a saying in IT circles: those who submit code without writing comments are as long as comments. A team can have multiple people working on a project at the same time, with no notes, and who knows what you write

Three. The way code comments

1. Single-line comments, using English symbols

Python: python: python: python: python: pythonCopy the code

2. Multi-line comments

Method 1: Use single quotation marks in English

2. Python 3. Python 4.Copy the code

Method 2: Use double quotation marks in English (similar to method 1)

"" python comment code 2 Python comment code 3 Python comment code 4 ""Copy the code

Method 3: Select one or more lines and press Ctrl+/

Python: python: python: python: python: pythonCopy the code

Note that: annotated code, the program in the execution of the time will be straight skip! Such as the following code:

#! Usr /bin/env python # -* -coding :utf-8 _*- "" www.codersrc.com @file :helloworld.py @time :2021/3/13 20:37 @Motto: No accumulation of small steps no thousands of miles, no accumulation of small streams no rivers and seas, the wonderful life of the program needs to be unremitting accumulation! """ print("hello word")Copy the code

This is a lot of code, but the compilation actually only executes the last line of code! Annotated code, the program automatically skip!

Four. Key summary

** In general, comments in Python programming have two functions: **

  • 1. Easy code reading
  • 2. The program will not execute commented code

Five. Guess you like it

  1. Introduction of Python
  2. Python Pycharm Anacanda difference
  3. Python2.x and python3. x, how to choose?
  4. Python Configuration Environment
  5. Introduction to Python Hello World

Python code comments

This article is published by the blog – Ape Say Programming Ape Say programming!