Python learning, python learning Manual

Source: Internet
Author: User

Python learning, python learning Manual
Python Learning

Python Study Notes (1)
Note: I learned this on the website of Miss Yu Xuefeng.
I. Basics
1.1 Python does not have a semicolon, and everything is implemented with indentation.
For example:
# Python form
A = 100
If a> = 0:
Print
Else:
Print-a # The comment behind it can be written at will.
In addition, Python is case sensitive. If an error is entered, an error is returned!
1.2 Python Data Types
1. Integer
2. Floating Point Number
3. String
When both "and" are used in the string, Transfer Character \ is used \
The method used is: "I \'m loutao"
\ N \ t is also an escape character.

Python allows the use of ''' and... to connect multiple rows. For example:
>>> Print ''' line1
... Line2
... Line3 '''
Line1
Line2
Line3

Boolean value: There are only True and False values. The Join Operation of Boolean values involves the and or not operation, which is quite simple as long as the mathematics is better.
Null Value: Null Value in Python is expressed as None. 0 and None indicate different meanings.

1.3 character encoding: because the computer can only process numbers, if you want to process text, you must first convert the text into numbers before processing.
ASCII encoding: one byte, which is good for English and cannot be used to convert Chinese characters into numbers that can be processed by computers. For example, the ASCII code of a is 97.
Unicode encoding: put all the language encodings of different countries into it. Generally, two bytes are used, and four bytes are used for Some uncommon characters. However, this may sometimes cause waste.
Because A only needs one byte, And in this encoding, two or more bytes are required. Then, the chance is to add 00000000 before A and 00000000 to 01000001.
UTF-8 encoding: Because Unicode is used to represent English, two bytes are used to waste one byte, so UTF-8 is used. UTF-8 uses three bytes in Chinese. The English language is 1 byte, which is common in various languages.

Format: python format is the same as c format. Integer: % d floating point: % f String: % s hexadecimal INTEGER: % x
Example: >>> 'Hi, % s, you have $ % d. '% ('Michael, 1000000)
'I, Michael, you have $1000000 .'
The 1.4 List and tuple python collections are similar to arrays in c.
Usage of List: stu = ['stu1', 'stu2'] stu = ['stu1', ['stu2', 'stu3. The append method adds elements to the end of the List, and the Pop method adds the last Pop-up stack of the List,
You can add an index pop (I );
Usage of tuple: stus = ('stu1', 'stu2'); as compared with List, tuple cannot be changed once defined.
1.5 dict and set: dict is a python built-in dictionary that can be used for fast query. The key of dict must be an unchangeable object.
Example: >>> d = {'Michael ': 95, 'bob': 75, 'tracy': 85}
>>> D ['Michael ']
95

Similar to dict, set is also a set of keys, but does not store values. Because keys cannot be repeated, there are no duplicate keys in the set.
Repeated elements are automatically filtered in the set: >>> s = set ([1, 1, 2, 2, 3, 3]) >>> s set ([1, 2, 3])
The remove (key) method class can delete the elements in the set.


Python is complete and authoritative. There are PDF, chm, and online versions. Each version of python will publish a Document of the same version, which can distinguish the differences between different versions of python.
In addition, as long as python has mastered the basic syntax, it can write a program. The process of writing a program is a familiar process of the module. Languages such as python and perl do not play a major role in themselves. They rely on their built-in modules or third-party modules to reflect their power.
Based on your purpose, we recommend several modules:
1. parsing documents: string and re modules. Re is a regular expression module, which is very important. Regular Expressions are proud of languages like python and perl.
2. capture data from the web page: urllib and urllib2 modules and re modules are generally enough.

The python installation packages are included in the modules mentioned above and do not need to be downloaded separately.

Find an example when writing the code, write it for analysis, and read it several times.
Python has a book called <Python UNIX and Linux System Management Guide>. It's hard to find a paper version.

Related Article

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.