Python Tutorial: Learn Python in Just 1 Hour!

Follow 👆 the public account and reply 'python' to receive the beginner's tutorial! Source from the internet, delete if infringing

1. Hello World

After installing Python, open IDLE (Python GUI). This program is the Python language interpreter, and the statements you write can run immediately.

[Tutorial The method of obtaining is at the end of the article!!]

[Tutorial The method of obtaining is at the end of the article!!]

We write a famous program statement:

Python Tutorial: Learn Python in Just 1 Hour!

Press Enter, and you will see this famous quote introduced into the programming world by K&R. In the interpreter, choose “File” — “New Window” or use the shortcut Ctrl+N to open a new editor.

Write the following statement:

Python Tutorial: Learn Python in Just 1 Hour!

Save it as a.py file.

Press F5, and you will see the program’s running result.

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 a different way. Create a new editor and write the following code:

Python Tutorial: Learn Python in Just 1 Hour!

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

Python Tutorial: Learn Python in Just 1 Hour!

Change the character set to a more familiar form:

Python Tutorial: Learn Python in Just 1 Hour!

The program runs well as usual.

3. Convenient and Easy-to-use Calculator

Using the calculator that comes with Microsoft is really cumbersome. Open the Python interpreter and calculate directly:

Python Tutorial: Learn Python in Just 1 Hour!

4. Strings, ASCII, and UNICODE

You can print predefined formatted strings as follows:

Python Tutorial: Learn Python in Just 1 Hour!

How are strings accessed? Please see this example:

Python Tutorial: Learn Python in Just 1 Hour!

Please note the difference between ASCII and UNICODE strings:

Python Tutorial: Learn Python in Just 1 Hour!

5. Using Lists

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

Python Tutorial: Learn Python in Just 1 Hour!

6. Conditional and Loop Statements

Python Tutorial: Learn Python in Just 1 Hour!

7. Defining Functions

Python Tutorial: Learn Python in Just 1 Hour!

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

Python Tutorial: Learn Python in Just 1 Hour!

8. File I/O

Python Tutorial: Learn Python in Just 1 Hour!

9. Exception Handling

Python Tutorial: Learn Python in Just 1 Hour!

10. Classes and Inheritance

Python Tutorial: Learn Python in Just 1 Hour!

11. Package Mechanism

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

Python Tutorial: Learn Python in Just 1 Hour!

Python Tutorial: Learn Python in Just 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 subfolder, and the child contains a module a.py.

How does Python know this file structure? It’s simple; each directory has a file named __init__.py. The content of this file can be empty.

This structure is shown below:

Python Tutorial: Learn Python in Just 1 Hour!

So how does Python find the modules we defined? In the standard package sys, the path attribute records the Python package paths. You can print it out:

Python Tutorial: Learn Python in Just 1 Hour!

Usually, we can put the module’s package path into the environment variable PYTHONPATH, and this environment variable will be automatically added to the sys.path attribute.

Another convenient method is to directly specify our module path into sys.path in the code:

Python Tutorial: Learn Python in Just 1 Hour!

12. Summary

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 skilled programmer should be quite familiar with these concepts, so after you squeeze out an hour to read this short tutorial, you can quickly get familiar with Python through the transfer analogy of existing knowledge and start programming with it. Of course, the idea of learning Python in 1 hour is a bit sensational.

To be precise, programming languages include syntax and standard libraries.

Syntax is equivalent to martial arts moves, while standard library application practice experience is similar to internal skill, which requires long-term training.

Python has learned from the strengths of Java, providing a large number of very convenient standard libraries for programmers to utilize. (This is also the reason for Python’s success).

How to Obtain:

  1. Like + Look Again

  2. Reply in the public account: “python”

Get the latest 2024 Python beginner learning materials,Reply in the backend:Python

Leave a Comment