Python from getting started to giving up QAQ

1. Python founder and development history

  吉多·范罗苏姆,1989年python出生。

In 1991, a python compiler was born. It was implemented in C language and was able to call C language library files.

In 2008, Python launched versions 2.6 and 3.0. Because the 2.6 version has violated Uncle Turtle’s idea of ​​creating python, which is concise, beautiful, clear and simple, Uncle Turtle introduced his own modified 2.6 and the newly launched 3.0, and said that he will not Then update version 2.0.

Second, the scope of python application

Python can be applied to many fields such as data analysis, component inheritance, network services, image processing, numerical computing and scientific neighborhoods.

Three, what kind of language is python

1. Programming languages ​​are mainly classified from the following perspectives, compiled and interpreted, static and dynamic languages, strongly typed definition languages ​​and weakly typed definition languages.

2.What is the difference between compilation and interpretation?

The compiler compiles every statement of all source programs into binary, so that the machine can be used to run directly, and the program runs very fast.

The interpreter interprets the binary code one by one when the program is executing, so the running speed is slow, not as fast as the compiled running program.

Insert picture description here

3. Compiled languages ​​have

C \ C++ \ GO \ Swift \ Object-c \ Pascal

  解释型语言有

JavaScript \ Python \ Ruby \ PHP \ Perl \ Erlang

Mixed languages ​​have

JAVA \ C #

Fourth, the advantages and disadvantages of compiled and interpreted

Compiled

Advantages: The compiled type will have a pre-compilation process to optimize the code. Because it is only compiled once and does not need to be compiled at runtime, the compiled type has a high execution efficiency and can run independently from the language environment.

Disadvantages: If you need to re-modify after compilation, you need to recompile the entire module. When compiling, the machine code is generated according to the corresponding environment. There will be problems in porting between different operating systems. Different executable files need to be compiled according to the operating operating system environment. 4

Interpretive

Advantages: Good platform compatibility, can run in any environment, provided that an interpreter (virtual machine) is installed. Flexible, you can directly modify the code when you modify the code, and it can be deployed quickly without downtime for maintenance.

Disadvantages: You have to explain it every time you run it, and the performance is not as good as the compiled type.

Five, the advantages and disadvantages of python

advantage

1. Python positioning, clear, elegant and simple.

2. High development efficiency, python has a very powerful third-party library.

3. High-level language.

4. Portability.

5. Scalability.

6. Embeddability.

Disadvantage

1. The speed is slow.

2. The code cannot be encrypted.

3. The problem that threads cannot use multiple CPUs.

Five, python's interpreter

CPython

Running python on the command line is to start the CPython interpreter.

CPython is the most widely used python interpreter.

IPython

IPpython is an interactive interpreter based on CPython. IPython is only enhanced in interactive mode. The function of executing python code is the same as that of CPython.

PYPY

PyPy's goal is execution speed, dynamically compiling (not interpreting) python code, so it can significantly improve the execution speed of python code.

Jython
Jython is a Python interpreter running on the Java platform, which can directly compile Python code into Java bytecode for execution.

IronPython
IronPython is similar to Jython, except that IronPython is a Python interpreter running on the Microsoft .Net platform, which can directly compile Python code into .Net bytecode.

Six, variables and constants

1. Variables

Variable: Temporarily store the intermediate result of the operation in the memory for subsequent program call. Rules for naming
variables : 1. Variables are composed of letters, numbers, and underscores.
2. Cannot be used The beginning of the number, not to mention the whole number

3,不能是pythond的关键字, 这些符号和字⺟母已经被python占⽤用, 不可以更更改

4,不要⽤用中⽂文

5,名字要有意义

6,不要太⻓长

7, 区分⼤大⼩小写

It is recommended that everyone use the camel case or underscore to name the camel case: every word except the first letter is written at the beginning of the letter and the letter is underlined: each word is separated by an underscore

2. Constant

There are no absolute constants in python. Conventionally, all capital letters are even constants.

Example: PI = 3.1415926

   BIRTH_SYLAR = 1990

Seven, notes

Single-line comment: #The content of the comment

Multi-line comment: #"""Commented content"""'''This is also a multi-line comment'''

Eight, the basic data types of python

1. Integer (int)

Common numbers are int, used for calculation or size comparison.

The range of int on a 32-bit machine is -2 31~2 31-1, which is -2147483648~2147483647

The range of int on a 64-bit machine is: -2 63~2 63-1, which is -9223372036854775808~9223372036854775807

2. String (str)

In python, everything enclosed in quotation marks is a string.

Strings can be used, single quotation marks, double quotation marks, triple quotation marks, there is no difference, but some special formats require unused quotation marks.

msg = "My name is Alex, I'm 22 years old!" This requires single and double quotes.

msg = “”"

Today I want to write a small poem,

Sing to my tablemate,

Look at his short black hair,

It looks like a fried chicken.

“”"

To assign a string in multiple lines, triple quotation marks are required.

Is there a ±*/ string for numeric types?

The string string only has + *.

#String string splicing

s1 = 'a ’

s2 = ‘bc’

#print(s1 + s2) #Multiply
str*int

name ='strong'

#print(name*8)

Nine, user interaction

Using the input() function, we can interact with the computer

grammar:

Content = input (prompt information)

Here you can directly get the content entered by the user

Flow control if statement

The first syntax:

if 条件:             #引号是将条件与结果分开。

     结果1。        # 四个空格,或者⼀一个tab键,这个是告诉程序满⾜足这个条件的  

结果2。 如果条件是真(True) 执⾏行行结果1, 然后结果2, 如果条件假(False) 直接结果2

The second syntax:

If 条件: 

   结果1

else:

    结果2

代码3

The third syntax:

If condition 1:

   结果1

elif 条件2:

   结果2

.. 

else:

    结果n

The fourth syntax (nested):

If 条件1: 

   结果1

    If 条件2:

      结果2 

   else: 

       结果3

    else:

    结果4  

  可以⽆无限的嵌套. 但是在实际开发中. 尽量量不要超过三层嵌套

Guess you like

Origin blog.csdn.net/weixin_43214644/article/details/115035675