Beginner Python Tutorial: Learn Python in 1 Hour

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!!]

[TutorialGet it at the end of the article!!]

Let’s write a famous program statement:

Beginner Python Tutorial: Learn Python in 1 Hour

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:

Beginner Python Tutorial: Learn Python in 1 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 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:

Beginner Python Tutorial: Learn Python in 1 Hour

When you save the code, Python will prompt you to change the file’s character set, as shown below:

Beginner Python Tutorial: Learn Python in 1 Hour

Change the character set to a more familiar format:

Beginner Python Tutorial: Learn Python in 1 Hour

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:

Beginner Python Tutorial: Learn Python in 1 Hour

4. Strings, ASCII, and UNICODE

You can print predefined formatted strings as follows:

Beginner Python Tutorial: Learn Python in 1 Hour

How are strings accessed? See this example:

Beginner Python Tutorial: Learn Python in 1 Hour

Note the difference between ASCII and UNICODE strings:

Beginner Python Tutorial: Learn Python in 1 Hour

5. Using Lists

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

Beginner Python Tutorial: Learn Python in 1 Hour

6. Conditional and Loop Statements

Beginner Python Tutorial: Learn Python in 1 Hour

7. Defining Functions

Beginner Python Tutorial: Learn Python in 1 Hour

Moreover, here is a convenient and easy-to-use function:

Beginner Python Tutorial: Learn Python in 1 Hour

8. File I/O

Beginner Python Tutorial: Learn Python in 1 Hour

9. Exception Handling

Beginner Python Tutorial: Learn Python in 1 Hour

10. Classes and Inheritance

Beginner Python Tutorial: Learn Python in 1 Hour

11. Package Mechanism

Each .py file is called a module, and modules can import each other. See the example below:

Beginner Python Tutorial: Learn Python in 1 Hour

Beginner Python Tutorial: Learn Python in 1 Hour

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:

Beginner Python Tutorial: Learn Python in 1 Hour

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:

Beginner Python Tutorial: Learn Python in 1 Hour

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:

Beginner Python Tutorial: Learn Python in 1 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 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.

Beginner Python Tutorial: Learn Python in 1 Hour

How to Get:

  1. Like + See Again

  2. Reply with ‘python’ in the public account

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

Leave a Comment