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 basic basic knowledge is needed to learn Python

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

Share

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

Editor to share with you to learn Python need to know what basic knowledge, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

I. programming development specification

As a development language, python naturally has its own programming specifications, and the following are unique and must be followed:

1. The beginning of the code: the code in python must be written in the top box unless it is nested in a conditional judgment or condition loop as a statement.

two。 Code level: the logical hierarchical relationship between code and code (involving logical judgment, inclusion relationship, etc.) is defined by spaces, the top space of the first layer is written, and 4 spaces are reserved at the beginning of the second layer (including or executing actions after logical judgment) (tab can be used if cross-platform is not considered)

3. Alignment: code at the same level must be strictly aligned, such as the first layer has top spaces, the second layer starts with 4 spaces, the third layer has 8 spaces, and so on.

4. Comments: a single-line comment begins with #, a single line as a comment or a comment followed by # after the code. Multiple-line comments can be quoted in pairs of three quotation marks at the beginning and the end, and can be three single quotes or three double quotes in pairs.

5. Code block: the if logic judgment and the for loop condition all end with a colon, and then write the actual execution action statement at the next level with four spaces. The statement followed by the colon is called a code block.

6. Program naming: python programs must end with .py.

7. Project specification: when starting a project development, first create a project in the development tool, then create a directory as needed, and finally create a currently active py program under the directory.

Second, variables

Variables in Python are also used to store temporary values for subsequent flexible calls, which can only be defined with any combination of letters, numbers, and underscores, and cannot start with a number or name variables with python built-in keywords (such as and,import,global,finally, etc., which need to be further studied to deepen the impression). When assigning a string type to a variable, the string needs to be enclosed in pairs of quotation marks, which can be single, double, or triple quotes.

III. Character coding

Because character coding is of great importance, a word disagreement will lead to garbled code, so it is strongly recommended to use universal utf-8 coding.

4. Python interpreter

Python is an interpretive language, so you can't do without an interpreter (similar to JVM). Cpython, Jpython, Ironpython and pypy are officially supported, and Cpython based on C language is used by default. It is also the most widely used interpreter. When the program runs, it converts the .py file into a .pyc bytecode file, and then runs it on the python virtual machine.

Fifth, build the development environment of Python

Building a Python development environment, including the interpreter (virtual machine) and the development tool IDE, can facilitate the development of the program.

VI. First acquaintance of modules

Python has a lot of modules built in, and you can also customize and write some fun modules, which need to be imported through the keyword import when using the module. After import, python will go from the path of the system variable to the next search, and there will be no subsequent search after the first successful match. So if you need to use a custom module, you need to pay special attention to where the custom module is stored, and the bottom line is to store it only under a path of the system variable, otherwise you may get unexpected results.

VII. User input and formatted output

User input is realized through input

Simple output is achieved through print

VIII. The running logic of Python

The working logic of Python is as follows:

Memory loading code-> parsing-> interpreter loading-> generating bytecode-> executing bytecode-> generating machine code-> CPU execution

The above is all the contents of the article "what basic knowledge you need to know to learn Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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