current position:Home>Comments and variables in Python
Comments and variables in Python
2022-01-30 21:09:42 【Don't laugh and meditate】
This is my participation 11 The fourth of the yuegengwen challenge 1 God , Check out the activity details :2021 One last more challenge
notes
What is annotation
- It won't be in the code Python Directly run statements
Why use notes
- Facilitate the later reading of the code
- Facilitate the later maintenance of the code
Three uses of annotations
# |
Single-line comments |
---|---|
''' ''' |
Multiline comment |
""" """ |
Multiline comment |
Python Script execution entry
What is a script entry
- The execution of the program also needs such an entry
- — Generally, we call the entry of code execution as the main function main
How to write code script
If your name is Xiaoming .py, In the eyes of friends , You are Xiaoming (__name_==‘ Xiao Ming ’__
);
In your own eyes , You are yourself ( __name_ == '__main_'
)
Indent
# coding:utf-8
import os
if __name__ == '__main':
print(os.getcwd())
print(" I return 1 Level code block ")
Copy code
- Indent the same level of proof code
For the code entry, hope is the last of the code
Variable
What is a variable
for instance :
Prepare a glass , We can pour coke into the glass or sprite into the glass , The glass doesn't change during this process , What changes is the liquid in the glass . Here we can think of the glass as a variable name , Treat the liquid in the glass as a variable value, and this process is assignment .
Pictured :
summary : What is a variable
- Assignment statement
- You can change the value by assigning a value to the variable name
- The variable name can remain unchanged , Variable values can be changed
- A variable name with a variable value —— Variable
Where do you live
- Variables exist in the memory of our computer
- Each variable is defined and stored in a memory block
Rules for variable names
- form : It has to be numbers , Letter , Underline composition
- length : Any length , But not too long ,20 Within characters
- requirement : Must start with a letter
- Be careful : Case sensitive 、 meaningful
Common errors about variables
# The variable name naming rule is wrong, and the error message
SyntaxError: invalid token
# Using undefined variables
NameError: name 'worker' is not defined
Copy code
Defining variables
# coding: utf-8
usename = ' Xiaomo '
age = 20
is_sleep = 'ok'
is_eat,is_learn,is_play = 'yes','no','no'
#01work='01'
if __name__ == '__main__':
print(usename)
print(age)
print(is_sleep)
print(is_eat)
print(is_learn)
print(is_play)
#print(worker)
Copy code
Be careful : If you define multiple variables on the same line , Then the defined variable value must correspond to the variable name one by one , Otherwise, an error will be reported
Error message :ValueError: not enough values to unpack (expected 3, got 2)
copyright notice
author[Don't laugh and meditate],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201302109401838.html
The sidebar is recommended
- Introduction to python (IV) dynamic web page analysis and capture
- leetcode 119. Pascal's Triangle II(python)
- leetcode 31. Next Permutation(python)
- [algorithm learning] 807 Maintain the city skyline (Java / C / C + + / Python / go / trust)
- The rich woman's best friend asked me to write her a Taobao double 11 rush purchase script in Python, which can only be arranged
- Glom module of Python data analysis module (1)
- Python crawler actual combat, requests module, python realizes the full set of skin to capture the glory of the king
- Summarize some common mistakes of novices in Python development
- Python libraries you may not know
- [Python crawler] detailed explanation of selenium from introduction to actual combat [2]
guess what you like
-
This is what you should do to quickly create a list in Python
-
On the 55th day of the journey, python opencv perspective transformation front knowledge contour coordinate points
-
Python OpenCV image area contour mark, which can be used to frame various small notes
-
How to set up an asgi Django application with Postgres, nginx and uvicorn on Ubuntu 20.04
-
Initial Python tuple
-
Introduction to Python urllib module
-
Advanced Python Basics: from functions to advanced magic methods
-
Python Foundation: data structure summary
-
Python Basics: from variables to exception handling
-
Python notes (22): time module and calendar module
Random recommended
- Python notes (20): built in high-order functions
- Python notes (17): closure
- Python notes (18): decorator
- Python notes (16): generators and iterators
- Python notes (XV): List derivation
- Python tells you what timing attacks are
- Python -- file and exception
- [Python from introduction to mastery] (IV) what are the built-in data types of Python? Figure out
- Python code to scan code to pay attention to official account login
- [algorithm learning] 1221 Split balanced string (Java / C / C + + / Python / go / trust)
- Python notes (22): errors and exceptions
- Python has been hidden for ten years, and once image recognition is heard all over the world
- Python notes (21): random number module
- Python notes (19): anonymous functions
- Use Python and OpenCV to calculate and draw two-dimensional histogram
- Python, Hough circle transformation in opencv
- A library for reading and writing markdown in Python: mdutils
- Datetime of Python time operation (Part I)
- The most useful decorator in the python standard library
- Python iterators and generators
- [Python from introduction to mastery] (V) Python's built-in data types - sequences and strings. They have no girlfriend, not a nanny, and can only be used as dry goods
- Does Python have a, = operator?
- Go through the string common sense in Python
- Fanwai 4 Handling of mouse events and solutions to common problems in Python opencv
- Summary of common functions for processing strings in Python
- When writing Python scripts, be sure to add this
- Python web crawler - Fundamentals (1)
- Pandas handles duplicate values
- Python notes (23): regular module
- Python crawlers are slow? Concurrent programming to understand it
- Parameter passing of Python function
- Stroke tuple in Python
- Talk about ordinary functions and higher-order functions in Python
- [Python data acquisition] page image crawling and saving
- [Python data collection] selenium automated test framework
- Talk about function passing and other supplements in Python
- Python programming simulation poker game
- leetcode 160. Intersection of Two Linked Lists (python)
- Python crawler actual combat, requests module, python to grab the beautiful wallpaper of a station
- Fanwai 5 Detailed description of slider in Python opencv and solutions to common problems