Python Learning Notes

Python Basics

annotation

The role of comments

By using their familiar language, in the program to annotate some code, this is the role of comments, can greatly enhance the readability of the program.

Classification and syntax of annotations

  • Single-line comments
    # Comment content
Copy the code
  • Multiline comment
""" First line comment second line comment third line comment """
Note 1 note 2 Note 3"
Copy the code

Shortcut key: CTRL + /

variable

Function of variables

In the program, data is temporarily stored in memory. In order to find or use the data more quickly, we usually define a name after storing the data in memory, and the name is variable.

A variable is simply the name of the memory location where the data is stored.

Define variables

Variable name = value# Custom variable name, to meet the identifier naming rules.
Copy the code
identifier

Identifiers are the common conventions for defining names in Python, as follows:

  • The value consists of digits, letters, and underscores (_)
  • Can’t start with a number
  • Built-in keywords cannot be used
  • Strictly case sensitive

False None True and as assert break class continue def del elif else except finally for from global if import in is lambda nonlocal not or pass raise return try while with yield

Naming habits
  • The name shows the meaning.
  • Big hump: capitalized every word, for example, MyName.
  • Small hump: capitalize the first letter of the word after the second (inclusive), e.g. MyName.
  • Underscore: For example, my_name.