PYTHON learning notes, python learning Manual

Source: Internet
Author: User

PYTHON learning notes, python learning Manual

Python learning abc
Christmas in 1989
Guido is now working on google
Before CNRI 1.5
BeOpen 2.0 and 1.6 are quite different.
Zope plug-in
Python3.0
2.0 2.6 2.7
Tianyi programming awards have the fastest growing share
Python features:
Script Language
Compilation and interpretation
Object-oriented
Advanced Language
Scalability and embedability
Free and open-source
Portability
Rich Libraries
Glue Language
Auxiliary scripts
Better than ruby
Build a Python Environment

Command: Check whether the Python environment is successfully installed.

Print 'Hello world! '

 

1. Download Python
Http: www.python.org/download
2. >>>: a prompt.
3,
1/2
1 // 2
1.0 // 2.0
% Remainder, ** power
Maximum: 2147483647
Minimum value:-2147483648.
If you really need a large number, you can use a long integer.
The long integer number is written in the same way as the ordinary integer, but the end has an L
Theoretically, L can be lowercase, but it is close to 1, so it is not recommended.
You can use a combination of a long integer and an ordinary integer. In most cases, you do not have to worry about the difference between a long integer and an integer.
Unless type check is required

4. print is a function in Python3.0.

5. input ("get user input :");
6. if usage:
If 1 = 2: print 'one equals two'
If 1 = 1: print 'one equals one'
If time % 60 = 0: print 'on the hour! '

7. Functions
Pow (2.3)
Abs (-10)
Round (1.0/2.0)
8. Module
Import math

From math import sqrt differences are not recommended
9. Differences between input and raw_input
Quotation marks for input
Raw_input is not required
10. Differences between str and repr
Str String Conversion is easy for users to read
Conversion from repr to string is a Python expression
10. Long String
It is no difference to replace the regular quotation marks with '''zifuchuanc''' or "string" with a single double quotation mark.
11. original string

 

 

Multiple numbers of import cmath
Unicode string
Unicode strings use the u prefix, just as the original string uses r.
All strings in Python3.0 are Unicode strings.

1. Sequence
Six built-in Sequences
List, tuples, strings, Unicode strings, buffer objects, xrange objects
List and metadata
Difference: the list can be modified. The tuples cannot be modified.
2. General sequence operations
Index, Shard, add, multiply, and check whether an element belongs to a Sequence member.
Python also provides built-in functions for calculating the sequence length and finding the maximum and minimum elements.
3. Index
All elements in the sequence increase progressively from 0 with numbers.
You can also use a negative index.
The string literal value can directly use the index without the need for a variable to reference them. For example:
'Hello' [1] Output 'E'
Fourth = raw_input ('year: ') [3]
4. Parts
Access element fragments within a certain range through the sharding operation using two indexes separated by colons.
Numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Numbers [3: 6]
Output: [4, 5, 6]
Numbers [0: 1
Output: [1]
The implementation of the sharding operation requires that two indexes be included in the shard as the first index element of the boundary, while the second index is not included in the shard.
Numbers [-3:]
[8, 9, 10]
Numbers [-] output is blank []
Numbers [:]
Numbers [: 3]
Larger step size
Numbers [0: 10: 1]
Numbers []
The step size can be a negative number. For a positive step, Python extracts elements from the header of the sequence to the right. For a negative step size, it extracts elements from the left end of the sequence.

5. Sequence Addition
You can use the plus sign to connect the sequence.
[1, 2, 3] + [4, 5, 6]
Output [1, 2, 3, 4, 5, 6]
'Hello. '+ 'World! '
List and string cannot be connected. Only two sequences of the same type can be connected.
6. Multiplication
Multiply the number X by a sequence to generate a new sequence. In the new sequence, the original sequence will be repeated X times.
None empty list and initialization
None is a Python built-in value.
7. Membership
In Operator
'W' in permissions
True or false is false.
8. length, minimum value, and maximum value
Len, min, max
9. List: 'cool' of Python'
The list function applies to all types of sequences, not just strings.
10. Basic list operations
Index, partition, join, and multiplication
1. Change the value of the list: Element assignment
2. You cannot assign a value to an element that does not exist.
3. Delete the element del names [2]
4. Partition assignment name [2:]
5. You can replace shards with sequences of different lengths from the original sequence.
6. The partition assignment statement can insert a new element without replacing any original element.
7. It is also feasible to delete elements through multipart assignment.

List Method
1. Object. Method (parameter) append such as lst. append is used to append a new object to the end of the list.
Count Method to count the number of times an element appears in the list
The extend method can append multiple values of another sequence at a time at the end of the list.
The index method is used to locate the first matching position of a value from the list.
Insert is used to insert objects to the list.
The pop method removes an element from the list (the last one by default) and returns the value of this element.
The pop method is the only list method that can modify the list and return element values (except none ).
The remove method is used to remove the first matching item from the list.
Remove is a method for changing the original position without return values. It changes the list but does not return values. This is opposite to the pop method.
The reverse method stores the elements in the list in reverse order. This method is the same as the remove and sort method, but does not return values.
The sort method is used to sort the list at the original position. x [:] is a very efficient way to copy the entire list. The other way to obtain the copy of the sorted list is to use the sorted function.

8. advanced sorting
The numbers. sort (cmp) sort method has two other optional parameters.
X. sort (key = len) and x. sort (reverse = true)
The cmp key reverse parameter can be used in the sorted function.
9. tuples: immutable Sequence
Like lists, tuples are also a sequence. The only difference is that tuples cannot be modified.
1. If you use commas to separate values, you will automatically create tuples.
2. tuples are enclosed in parentheses. Most of the time
3. Empty tuples can be expressed by two parentheses that do not contain content.
4. A comma must be added to the tuples of a value, even if there is only one value
5,
10. tuple Function
The functions of the tuple function are basically the same as those of the list function: Use a sequence as a parameter and convert it to a tuple. If the parameter is a tuple, the parameter is returned as is.
11. Basic tuples
1. Create and access tuples
2. The original shard or the tuple, just as the list Shard is still the list
Two important functions of yuanzu are irreplaceable.
1. tuples can be mapped (and set members) and used as keys ---- the list does not work.
2. tuples exist as the return values of many built-in functions and methods. That is to say, you must process tuples. As long as you do not try to modify tuples, processing tuples is to treat them as lists in most cases, unless you need to use methods that are not available for tuples such as index, the count list may better meet the sequence requirements.

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.