What language is Python

Python is an amazing language! Can do anything except not have children

Programming languages are classified in the following categories: compiled, static, dynamic, strongly typed and weakly typed

(1) Compiler: There is a program responsible for translation of our source code to convert the corresponding executable code, this process is Compile (Compile), and responsible for the compilation of the program is called the Compiler (Compiler). Mengy, the next group is: 7762, just combine the above two groups of letters according to the order, she will arrange learning. , whether you are Daniel or small white, is to change or want to enter the industry can understand progress together to learn together! There are development tools, a lot of dry goods and technical information to share!

(2) Generally speaking, when we talk about dynamic languages, static languages refer to dynamically typed languages and statically typed languages

(3) Dynamically typed language: refers to the language that does data type checking at run time. That is, when programming in a dynamically typed language, you never have to assign a data type to any variable; the language internally records the data type the first time you assign a value to a variable. The typical ones are Python and Ruby

(4) Statically typed languages: Data types are checked during compilation, that is, the data types of all variables are declared when the program is written. C/C++ is the best example of a statically typed language, along with C# and Java

What can Python do

1) Site back-end programmers: use it to single site, back-end services are easier to maintain. Such as: Gmail, YouTube, Zhihu, Douban

2) Automated operation and maintenance: Automated processing of a large number of operation and maintenance tasks

3) Data analyst: rapid development, rapid verification, analysis of data to get results

4) Game Developers: Usually embedded in games as game scripts

5) Automated testing: written as a simple implementation script and applied in Selenium/ LR to achieve automation.

6) Website development: build your own website with Django and Flask framework.

7) The crawler acquires or processes a large amount of information, such as downloading US TV series in batches, running investment strategies, climbing suitable housing sources, scripting tasks of system administrators, etc.

Specific everyday things like automatically backing up your MP3 player;

Also can make the website, many famous website like Zhihu, Youtube is written by Python;

Also can do network game backstage, many online game backstage is Python development.

In short, I can do a lot of things!

And Python is the mainstream language of artificial intelligence development, learning Python can be an artificial intelligence engineer.

<pre>Python </pre>

Advantages: simplicity, high development efficiency, high-level language, portability, extensibility, embedability

Disadvantages: slow, but relative, code cannot be encrypted, threads cannot take advantage of multiple CPUs

The Python interpreter

CPython, IPython, Pypy, Jython, IronPython

The installation of Python

Installation under Linux

Install sqlite – devel

yum -y install sqlite-devel

Install dependencies

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

Download and install

wget https://www.python.org/ftp/py…

mkdir -p /usr/local/python3

The tar ZXVF Python – 3.6.1. TGZ

CD Python – 3.6.1

./configure –prefix=/usr/local/python3

make

make install

Soft connection

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

The environment

vim ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH

source ~/.bash_profile

Installation under Windows

1. Download the installation package

It has software that can be downloaded for free

2, installation,

Default installation path: C:\python35

3. Configure environment variables

[right click computer] — “[properties] –” [advanced system Settings] — “[advanced] –” [environment variables] — “[in the second content box to find a line of variable named PATH, double-click] –> [Python installation directory to add to the variable value, with; split]

For example: the original value; C:\python35, remember the semicolon before

Introduction to Python

A character encoding

The Python interpreter encodes the content when it loads the code in the.py file (default ASCILL).

ASCII (American Standard Code for Information Interchange) is a computer coding system based on the Latin alphabet used primarily to display modern English and other Western European languages. It can only represent a maximum of 8 bits (one byte), that is: 2**8 = 256, so ASCII code can represent a maximum of 256 symbols.

Obviously, ASCII code cannot represent all the characters and symbols in the world, so a new code that can represent all characters and symbols is needed, namely: Unicode

Unicode is a character code used on computers. Unicode is created to solve the limitation of the traditional character encoding scheme. It sets up a uniform and unique binary encoding for every character in every language. It stipulates that although some characters and symbols are represented by at least 16 bits (2 bytes), that is: 2 **16 = 65536,

Note: this is a minimum of 2 bytes and may be more

UTF-8 is a compression and optimization of Unicode encoding. Instead of using a minimum of 2 bytes, UTF-8 classifies all characters and symbols: ASCII contents are stored in 1 byte, European characters are stored in 2 bytes, and East Asian characters are stored in 3 bytes…

Python 3.x supports Unicode by default, so you can display Chinese characters directly without declaring the character encoding

annotation

Single-line gaze: # Comment content

Multiline comment: “”” Comment content “””

Comment shortcut key: select the comment content, Ctrl +? Comment the selected content, again Ctrl +? uncomment

The keyword

Python has some special-purpose identifiers, called keywords

Keyword is already used by Python, so developers are not allowed to define identifiers with the same name as the keyword

and as assert break class continue def del

elif else except exec finally for from global

if in import is lambda not or pass

print raise return try while with yield

You can view the keywords in the following way

<pre>import keywordprint(keyword.kwlist)</pre>

Formatted output

Little cute, add me WeChat: mengy7762

Receive the following benefits

3. Three copies of Python project source code: (Python cracking WiFi password, VIP video permission cracking, and crawler automation) 4. PPT teaching plan for basic learning 5. 30) Free choice. 6) Sharing of programmer career planning. 7) Making money in spare time

variable

<pre> Rules for variable definitions: Variable names can only be any combination of letters, numbers, or underscores The first character of a variable name cannot be a number Keyword cannot be declared as a variable name </pre>

The operator

Commonly used data type conversions

statement

if-else

<pre>if condition: things to do if condition satisfies 1 things to do if condition satisfies 2 things to do if condition satisfies 3… (omitted)… 1 Things to do if your condition is not met 2 Things to do if your condition is not met 3… (omitted)… </pre>

Example:

Name = input(‘ Please enter user name: ‘)

Password = input(‘ Please enter password: ‘)

if name == ‘root’ and password == ‘123’:

print(‘root login success’)

else:

Print (‘ username or password error ‘)

elif

<pre>if xxx1: Thing 1elif xxx2: Thing 2elif xxx3: Thing 3</pre>

  • When xxx1 is satisfied, thing 1 is executed, and then the whole if ends
  • If XXX1 does not satisfy, then XXX2 is judged, if XXX2 does, then thing 2 is executed, and the whole if ends
  • If XXX1 is not satisfied, then XXX2 is also not satisfied, and if XXX3 is, then thing 3 is executed, and then the whole if ends

Example:

If the nested

<pre>if condition 1: do something if condition 1: do something if condition 1… (omitted)… If condition 2: satisfies condition 2 to do thing 1 satisfies condition 2 to do thing 2… (omitted)… </pre>

Looping statements

The while loop

<pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > (omitted)… </pre>

Example: Sum 1 to 100

While loops are nested

<pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > <pre> > (omitted)… While condition 2 is satisfied, we do something while condition 2 is satisfied 3… (omitted)… </pre>

Example: The multiplication table

Results:

The for loop

In Python, a for loop can traverse any sequence of items, such as a list or a string.

<pre>for a temporary variable in a list, string, etc. </pre> for a temporary variable in a list, string, etc. <pre>for a temporary variable in a list, string, etc

Example:

<pre>name = ‘derek’for i in name: print(i)</pre>

Break and continue

<pre>break > Continue loop </pre> break > Continue loop </pre> break > Continue loop </pre> break > Continue loop </pre>

Depth copy

To understand deep and shallow copy, you need to understand the following concepts

Variable-reference-object (mutable object, immutable object) -slice-copy (shallow copy, deep copy)

A variable is an element of a system table that has space for a connection to an object

An object is an allocated chunk of memory that stores the values it represents

A reference is an automatically formed pointer from a variable to an object

In Python, immutable objects are objects that are immutable once created, including strings, primitives, and numbers

In Python, mutable objects are objects that can be modified, including lists and dictionaries

Assignment of immutable objects

If the value of a changes, B doesn’t change

Mutable object assignment

The value of a changes, so does the value of b

If the value of b does not change, you need to use the copy module

Depth copy

Shallow copy: Only copy top-level objects, or parent objects

Deep copy: Copies all objects, top-level objects and their nested objects. In other words: parent objects and their children

conclusion

  • Deep and shallow copies are copies of the source object and occupy different memory space
  • If the source object has only a level 1 directory, any changes made by the source do not affect the deep or shallow copy object
  • If the source object is more than a level 1 directory, any changes made to the source will affect the shallow copy, but not the deep copy
  • Slices of sequence objects are actually shallow copies, that is, only the top-level objects are copied