Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

When you save the code, Python will prompt you to change the file’s character set, resulting in the following:

Comprehensive Python Tutorial: Master Python in Just One Hour!

Change this character set to a more familiar format:

Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

4. Strings, ASCII, and UNICODE

You can print out predefined formatted strings as follows:

Comprehensive Python Tutorial: Master Python in Just One Hour!

How are strings accessed? Please see this example:

Comprehensive Python Tutorial: Master Python in Just One Hour!

Please note the difference between ASCII and UNICODE strings:

Comprehensive Python Tutorial: Master Python in Just One Hour!

5. Using List

Similar to List in Java, this is a convenient and easy-to-use data type:

Comprehensive Python Tutorial: Master Python in Just One Hour!

6. Conditional and Loop Statements

Comprehensive Python Tutorial: Master Python in Just One Hour!

7. Defining Functions

Comprehensive Python Tutorial: Master Python in Just One Hour!

And, introduce a convenient and easy-to-use function:

Comprehensive Python Tutorial: Master Python in Just One Hour!

8. File I/O

Comprehensive Python Tutorial: Master Python in Just One Hour!

9. Exception Handling

Comprehensive Python Tutorial: Master Python in Just One Hour!

10. Classes and Inheritance

Comprehensive Python Tutorial: Master Python in Just One Hour!

11. Package Mechanism

Each .py file is called a module, and modules can import each other. Please refer to the following example:

Comprehensive Python Tutorial: Master Python in Just One Hour!

Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

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:

Comprehensive Python Tutorial: Master Python in Just One Hour!

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

Comprehensive Python Tutorial: Master Python in Just One Hour!

How to Obtain:

  1. Like + Rewatch

  2. Reply ‘python’ in the public account

Get the latest 2024 Python zero-based learning materials, reply in the background:Python

Leave a Comment