Follow the public account👆 and reply with 'python' to get the beginner tutorial! Source from the internet, infringement will be deleted.
1. Hello World
After installing Python, open IDLE (Python GUI), which is the Python language interpreter, and your written statements can run immediately.
[TutorialGet it at the end of the article!!]
Let’s write a famous program statement:
Press enter, and you will see this famous quote introduced to the programming world by K&R.
Select “File” — “New Window” or use the shortcut Ctrl+N to open a new editor.
Write the following statement:
Save it as a.py file.
Press F5, and you will see the program’s output.
This is the second way to run Python.
You can also double-click the saved a.py file to see the program result.
Python programs can run directly, which is an advantage compared to Java.
2. Internationalization Support
Let’s greet the world in another way. Create a new editor and write the following code:
When you save the code, Python will prompt you to change the file’s character set, as shown below:
Change the character set to a more familiar format:
The program runs just fine.
3. Convenient and Easy-to-Use Calculator
Using the calculator that comes with Microsoft is really cumbersome. Open the Python interpreter and do calculations directly:
4. Strings, ASCII, and UNICODE
You can print predefined formatted strings as follows:
How are strings accessed? See this example:
Note the difference between ASCII and UNICODE strings:
5. Using Lists
Similar to List in Java, this is a convenient and easy-to-use data type:
6. Conditional and Loop Statements
7. Defining Functions
Moreover, here is a convenient and easy-to-use function:
8. File I/O
9. Exception Handling
10. Classes and Inheritance
11. Package Mechanism
Each .py file is called a module, and modules can import each other. See the example below:
Modules can be defined inside packages.
The way Python defines packages is a bit quirky. Suppose we have a parent folder, which has a child folder, and the child contains a module a.py.
How does Python know this file structure? It’s simple; each directory should contain a file named __init__.py. The content of this file can be empty.
The structure looks like this:
So how does Python find the modules we defined? In the standard package sys, the path attribute records Python’s package paths. You can print it out:
Usually, we can put the module’s package path into the environment variable PYTHONPATH, which will automatically be added to sys.path.
Another convenient method is to directly specify our module path in sys.path during programming:
12. Conclusion
You will find this tutorial quite simple.
Many Python features are implicitly presented in the code, including:
Python does not require explicit declaration of data types, keyword explanations, string function interpretations, etc.
A proficient programmer should have a good understanding of these concepts, so that after spending a precious hour reading this short tutorial, you can quickly familiarize yourself with Python through the transfer of existing knowledge and start programming as soon as possible.
Of course, learning Python in one hour can be quite sensational.
To be precise, programming languages include syntax and standard libraries.
Syntax is equivalent to martial arts moves, while standard library application experience is similar to internal skills, which require long-term practice.
Python has learned from Java’s strengths and provides a wealth of very convenient standard libraries for programmers to utilize. (This is also the reason for Python’s success).
But in any case, at least now you can use Python instead of cumbersome batch processing to write programs. I hope those who can really finish this article in an hour and start using Python will enjoy this little article. Thank you!
[Comprehensive Compilation] “From Beginner to Proficient in Python Development” All notes of the Python basic tutorial are released.
How to Get:
-
Like + See Again
-
Reply with ‘python’ in the public account
Get the latest 2024 Python zero-based learning materials,Reply in the background:Python