“This is the second day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”
Write at the front 👀
There is an old saying called “Life is hard, I use Python” 🌝 Python has become one of the most popular programming languages in the world in recent years 🌍 Python is really friendly to beginners like me. Here is the basic use and syntax of Python3 🤞
Python3 download and install
- You can skip to Thonny because it comes with a python3.7 interpreter and doesn’t need another one of your own.
- Official Download link
- Rule over all kinds of hand parties(This version is:
3.8.10 win - 64
) - After the installation is complete, find the installation package, click Modify, and Add Python to Environment Variables. This allows you to run Python on an environment such as CMD. Other check box no special requirements can not point, directly next.
Choose an editor for your Python
1. Pycharm
PyCharm was developed by renowned software development company JetBrains. Like the development of artificial intelligence and machine learning, it is the first choice for programmers. Powerful, support web development, provide intelligent code function, can be more accurate and quick bug repair, support remote development. However, the interface is a little complicated, and the professional version is charged (you can also get a one-year free trial through the education mailbox or xuexin website, the author is currently applying). There is no special requirement that the community version is enough. Pycharm
2.VSCode
VSCcode developed by Microsoft, plug-ins rich, powerful, shortcut practical, remote development free, support a variety of languages, is considered by many programmers the best IDE editor. (I currently use it as the main) VSCode download address
3.Thonny
Thonny is considered a Python IDE for beginners, developed by the University of Tartu. Simple interface, not too many complex functions, easy to use. Thonny download address
- Since its installation package is on GitHub, the download will be slow or even impossible to open.
- If you, like me, can’t download, you can try PIP
- Open the CMD
Win +R Enter CMD and press Enter
- The input
pip install thonny
enter - If it’s still slow, you can use the mirror source, and then click through like an accelerator.
- Input:
pip install thonny -i https://mirrors.aliyun.com/pypi/simple/
- I have been down here.
- But Thonny under PIP has no desktop icon. Opening mode:
Win +R Enter Thonny and press Enter
Or in theControl panel address barThat’s the direct inputThonny
Try interacting with Python 👏
- Open CMD and typepythonAnd hit enter, see
>>>
The interface is displayed successfully. - Try to enter
Print (' Stubborn horn ')
And press enter. ctrl+Z
Exit the interaction,>>>
Disappear indicates successful exit.- If you are not familiar with command line operations, you can check out the following article 👇
Summary of CMD Common Commands Windows Users need to know – Zhihu (zhihu.com)
- You can see that the Python version is Win3.8.10
4. Python syntax features
1. Code format
- No special rules, use UTF-8 encoding
- Python features: Use
The indentation
To represent a block of code without curly braces{}
And the semicolon;
- It is best to represent an indent with four Spaces (although the number of indent Spaces is variable, statements in the same code block must contain the same number of indent Spaces)
- So Python is very useful for developing code specifications
2, comments,
#
Represents a single line comment' ' '
or"" "
Represents a multi-line comment- Note in the word editor will not read, usually write code to develop the habit of writing notes, convenient for themselves and others to read the code, because to the future real development to write tens of thousands of code, they do not know what is.
3. Identifier
The first character
Must be a letter or underscore _.- The rest is made up of
The letter
,digital
andThe underscore _
Composition. - right
case
Sensitive. (For example, Lzh and Lzh are two different identifiers) - Can’t!
The keyword
(for, while, if) as an identifier. Here is the Python keyword 👇
- There is no need to define variable data types in Python, which is why it has fewer keywords.
4, statements,
- It is usually one statement per line, but backslashes can be used if the statement is too long
\
Represents a multi-line statement.
2. If a list, dictionary, or tuple has multiple lines in [], {}, or (), do not use a backslash\
They are separated by commas as shown below
3. Use a semicolon (;) between multiple statements in the same line;
Segmentation (distinguish C, C language is used, segmentation) as shown below:
5, a blank line
- Unlike indentation, blank lines are not part of Python syntax. Write without inserting blank lines and run without error. However, blank lines are used to separate two pieces of code with different functions or meanings for future maintenance or refactoring. (The layman’s point is to make the code more readable and less crowded.)
- Blank lines are also part of the program code.
6. Print ()
- Unlike Python2,
Python3
In theprintThe default output is newline. To implement non-newline, add to the end of the variableend=""
See the picture below:
- without
end=""
There are no newlines in the multiplication table
- added
end=""
The multiplication table breaks
7, input(
- Wait for user input, press Enter and exit.
- Input () is a string, and it converts you to a string even if you type a number.
- A plus sign
+
Connecting and seamless, comma.
There’s also a link but there’s a space in between. type()
You can view data types
8. Other points to pay attention to ✨
- Punctuation must be in English, otherwise it will report errors.
- Write code to pay attention to the above mentioned specifications, more space and indentation, remember line breaks, multi-marked comments.
Write in the back
- Thanks for watching 💕
- Author ability is insufficient, welcome big guy to point out or supplement.