Follow 👆 the public account and reply with 'python' to get the zero-based tutorial! Source from the internet, please delete if infringed.
1. Hello World
After installing Python, open IDLE (Python GUI), which is the Python language interpreter where your statements can run immediately.
Let’s write a famous program statement:
Press Enter, and you will see this famous quote introduced to the programming world by K&R. In the interpreter, 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 see the program’s result by double-clicking the saved a.py file.
Python programs can run directly, which is an advantage compared to Java.
2. Internationalization Support
Let’s greet the world in a different 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, resulting in the following:
Change this character set to a more familiar format:
The program runs well as usual.
3. Convenient and Easy-to-Use Calculator
Using the calculator that comes with Microsoft is really troublesome. Open the Python interpreter and do calculations directly:
4. Strings, ASCII, and UNICODE
You can print out predefined formatted strings as follows:
How are strings accessed? Please see this example:
Please note the difference between ASCII and UNICODE strings:
5. Using List
Similar to List in Java, this is a convenient and easy-to-use data type:
6. Conditional and Loop Statements
7. Defining Functions
And, introduce 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. Please refer to the following example:
Modules can be defined inside packages.
Python’s way of defining packages is a bit quirky. Suppose we have a parent folder, which has a child subfolder, and the child contains a module a.py.
How does Python know this file hierarchy? It’s simple: place a file named __init__.py in each directory. The content of this file can be empty.
This hierarchy is shown below:
So how does Python find the module 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 be automatically added to the sys.path attribute.
Another convenient way is to directly specify our module path to sys.path in the code:
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 be quite familiar with these concepts, so that after squeezing out a precious hour to read this short tutorial, you can quickly familiarize yourself with Python through transfer learning from existing knowledge and start programming with it as soon as possible. Of course, the claim of mastering Python in one hour is 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, requiring long-term training.
Python has learned from Java’s strengths and provides a large number of very convenient standard libraries for programmers to adopt. (This is also the reason for Python’s success). But anyway, at least now you can use Python instead of cumbersome batch processing to write programs. I hope those who can really finish reading this article in one hour and start using Python will enjoy this little article, thank you!
[Comprehensive Compilation] “From Beginner to Proficient in Python Development” Python basic tutorial notes are all released
How to Obtain:
-
Like + Rewatch
-
Reply ‘python’ in the public account
Get the latest 2024 Python zero-based learning materials, reply in the background:Python