python tutorial - [1 hello, python]

content

➤ Getting to know python for the first time
➤ Building a python development environment
➤ Basic knowledge of python

Getting to know python

Python is an object-oriented high- level programming language written by Guido van Rossum during Christmas 1989.

As one of many programming languages, python has such characteristics as a complete basic code base and third-party libraries , "elegant", "clear" and "simple" design philosophy , and good cross-platform performance . Compared with the C language, the development efficiency of python is high. But with that comes the inefficiency of operation.

With the development of the field of artificial intelligence, python has gradually become popular. It is worth noting that python not only shines in the field of artificial intelligence, but also has its own advantages in network applications, scripting, etc. However, the ruler is long and the inch is short, and the characteristics of python itself also limit its application in some aspects. Such as: writing operating system (C language), writing mobile phone applications (Swift/Objective-C and java), etc.

Build a python development environment

Building a python development environment means installing a python interpreter and a suitable code editor on the computer, as well as debugging tools, etc. An integrated development environment (IDE) integrates the above functions. There are many excellent IDEs, and pycharm and Anaconda are recommended.

Currently, python has two versions, 2.x version and 3.x version. The two are incompatible with each other. Since the 3.x version is getting more and more popular. Therefore, this tutorial uses 3.x as an example.

You can download the latest version of the python interpreter by visiting the python official website. Its installation process varies depending on the operating system used. Note : It is best to add python to the environment variable during the installation process of the windows system, as shown in the following figure.

Add python to environment variables

At this point, the python interpreter has been installed into our computer. Next, I recommend two of the more popular code editors, notepad++ and sublime text 3.

So far, we have initially completed the construction of the python development environment. The following takes printing "Hello world!" as an example to illustrate the execution mode of the python program.

python basics

In the previous section, we gave the python program with only one line of code. Next, go through the basics of python through a slightly more complex program. code show as below:

 """
 此函数判断一个整数是否为素数。
 """
 def isprime(n):
     for i in range(2, int(n ** 0.5) + 1):
         if n % i == 0:
             return False
     return True

"""
此循环遍历20到100之间的所有整数并打印其中的素数。
"""    
for i in range(20, 101):  # 遍历20到100内的所有整数。
    if isprime(i) == True:  # 判断遍历到的整数是否为素数。
       print(i)  # 打印遍历到的素数。

The following features of the python language can be found in this program:

  • Comment : Use #as a single-line comment, use as a """..."""multi-line comment (single quotation marks can also be used).
  • Indentation : indicate the hierarchical relationship of the code. The only means of indicating program framework in python. When a statement ends with a colon, the indented statement is treated as a code block.
  • In addition, since python is an interpreted language, there is no need to declare variable types in advance when using variables. But need to be assigned.
  • Python uses the print() function and the input() function to complete basic input and output functions.

END

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325229966&siteId=291194637