First knowledge of python (1), first knowledge of python

Source: Internet
Author: User

First knowledge of python (1), first knowledge of python

1. Introduction to python

Python is an object-oriented, literal translation computer programming language. It is also a powerful and complete general-purpose language with more than a decade of development history, mature and stable. The Python syntax is simple and clear, and has rich and powerful class libraries. It is often called the glue language. It can easily connect various modules made in other languages. Python name comes from a comedy. Perhaps the people who initially designed the Python language did not expect that Python would be so widely used in industry and scientific research. Python was born in Guido. In fact, the first implementation is on a Mac machine. It can be said that Python was developed from ABC and was mainly influenced by Modula-3 (another pretty beautiful and powerful language designed for small groups. It also integrates the Unix shell and C habits. Currently, many companies on the market use streaming 2. X version, but 2. X has stopped updating, and 3.5 has optimized its original functions and libraries. Therefore, python will definitely be 3 in the future. x.

2. How to Build a python Environment

For windows, go to the official website to download the python program,

3. Program Encoding

ASCII (American Standard Code for Information Interchange) is a computer coding system based on Latin letters. It is mainly used to display modern English and other Western European languages, it can only be expressed in 8 bits (one byte), that is, 2 ** 8 = 256. Therefore, the ASCII code can only represent 256 symbols at most, but 256 obviously cannot meet the requirements of Chinese and other languages, so it produces a new encoding: Unicode

Unicode, also known as Wanguo code, is generated to address the limitations of traditional character encoding schemes. It sets a unified and unique binary encoding for each character in each language, it is specified that although some characters and symbols are represented by at least 16 bits (2 bytes), that is, 2*16 = 65536, The Wanguo code solves the limitations, because of its minimum limit of 2 bytes, the waste memory, in order to optimize this problem, the UTF-8 generated.

A UTF-8 is an optimization of Unicode encoding that no longer uses at least 2 bytes, but classifies all characters and symbols: the content in the ascii code is saved in 1 byte, the European characters are saved in 2 bytes, and the East Asian characters are saved in 3 bytes. Python 2.x is encoded in ASCII by default, while 3. x is the UTF-8.

4. Common Methods for python annotations

1. Single Row watching: # commented content

2. Multi-line comment: "commented content """

5. python Module

Module import method: import name, which can be roughly divided into three types

1. built-in modules

2. Internal Development Module

3. modules developed by programmers

6. pyc File

When you run the Python code. py file, a file with the same name is automatically generated during execution. pyc file, which is the bytecode generated after the Python interpreter is compiled. After decompiling, you can get the same code as the bytecode.

7. Variables

The declaration method is: name = value. The declaration rules are as follows:

1. Variable names can only be any combination of letters, numbers, or underscores

2. the first character of the variable name cannot be a number.

3. You cannot use the python keyword as the variable name.

8. Basic python statements

If and else, condition judgment statement.

  

1 i=02 if i==0:3     print ("zero")4 else:5     print ("no zero")

If the equation behind if is true, the program under if is executed; otherwise, the program under else is executed. I = 0, so 1 is 0, and the output is zero.

While loop statement, while is followed by an equation. If it is true, it is a loop. If it is not true, it is not a loop.

i=0while i<10:    i=i+1    print i

I cycles plus 1. When I becomes 10, the equation is not true and the loop ends.

Break, jump out of the loop body.

Continue, jump out of this loop and enter the next loop.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.