Python's core data types are numeric types, string types, list types, tuple types, dictionary types, file types, and other types, including collection types, class types, and none.
One, the number---immutable type
1. include int,long,float,complex
2.python of digital literals
Boolean type
Full type
Long integer type
Floating point number
Plural
3. Digital operation
+-*/Subtraction
Truncate DIVISION
* * exponentiation
% modulus
-X Unary Subtraction
+X One-dollar addition
4. Comparison operations
<< left Shift
>> Right Shift
& Bitwise AND
| bitwise OR
^ bitwise-With OR
~ Bitwise REVERSE
Second, sequence type
1. Sequence type
Sequence represents an ordered collection of objects that are indexed as non-negative integers
Lists and tuples are sequences of arbitrary Python objects
The character and metacharacters group belongs to an immutable sequence, and the list supports inserting, deleting, and replacing elements
All sequences support iterations
Applicable to all sequences of operations and methods
S[i] Index operator
S[I:J] for slice operator, s[i:j:sides] Extended slice
--the result of slicing produces a new memory object
Min (s) max (s) is used only for sequences that can be sorted on elements
Sum (s[, START]) applies only to the sequence of numbers
Number of elements in lens (s) s
All (s) to check if all items in s are true
Any (s) to check if any of the items in S are true
Variable Unpacking v1,v2,....=s
2. string---A sequence of characters
A. Character type
String literals: Put text in single quotes, double quotes, and three quotation marks (three quotation marks can be implemented across lines, and special characters are entered)
Cannot support international character set ( if Unicode encoding is used, the character U is used before the character, such as U "Laizetian")
Document string
The first statement of a module, class, or function is a character, and the string becomes a document document string, which can be called using the __doc__ property.
B. Manipulation of strings
byte string: Byte (8bit data) sequence
Unicode string: Unicode character (16bit data) sequence
--Python can save Unicode characters using 32bit integers, but this is an option
Operation:
S.captitalize first character uppercase
S.index (Sub [, Start [, end]]) finds the location of the first occurrence of the specified string
S.join (t) using S as a delimiter to concatenate strings in a sequence T
S.lower () converted to lowercase
S.replace (old, new[, Maxreplace]) Replace a substring
S.split ([Seq[,maxsplit]]) uses Sep as a delimiter to divide a string, Maxsplit is the maximum number of partitions
S.strip ([chrs]) Delete chrs opening and closing blanks or characters
S.upper () build a string into uppercase
3. List-- container type
A. An ordered set of arbitrary objects, accessing the elements through an index, is a mutable object, heterogeneous, arbitrarily nested
B. Support in situ modification--Modify references
---Modify the specified index element, modify the developed Shard, delete the statement, built-in method
C. Operation:
list addition L1+L2---- will not be modified in place, return a new list directly
L1*n L1 repeats n times---- Returns a new list
In----Member relationship qualifier, usage item in container
Not in
List parsing----[functions]: Generating a list
How to copy a list
l1=[1,1,1] L2=L1------ID Same
Import Cory L2=copy.deepcopy (L1)
l2=l1[:]
4. Tuple tuples
A.
Symbol expression ()
Container type: An ordered set of arbitrary objects that access the elements through an index, immutable objects, fixed lengths
Supports heterogeneous, nested
B. Operation
Define an empty tuple ()----() to omit
Tuple add +: Create a new tuple
T1*n repeat Operation N Times
in<----> not in
The tuple itself is immutable, but if a tuple has nested elements of a mutable type (such as a list), modifications to such elements do not return a new tuple
Third, the dictionary dict
1. Overview
Unordered data collection, also known as associative arrays or hash lists in other spur languages
Element access via key
Variable type container, variable length, supports heterogeneous, nested
2. Form
{Key1:value1,k2:v2,k3:v3 ...}
{} Empty Dictionary
3. Operation
Dictionary copy: d2=d1.copy (different ID)
Quick Build Dictionary: dict (' 123 ', ' XYZ ')
Returns an Iterator object:
D1.iteritems ()
I1=d1.itervaluse () I1.next ()----shown individually
I1=d1.iterkeys () I1.next ()----shown individually
I1=d1.iteritems () I1.next ()----shown individually
Iv. Collection
1. Overview
A collection is a set of unordered values that can be hashed
Support for set-relationship testing
Member relationship tests: in,not in, Iteration
index, element Fetch, slice not supported
Type of collection:set,frozenset
There is no specific syntax format, only the factory function can be created
2. Methods and operations for collection types
Len (s) returns the number of items in S
C.copy () make a copy of S
S.difference (t) differential set, returning all items in S, but not in T
S.intersection (t) to intersect, returning all items in S and T
S.isdisjoint (t) returns True if S and t do not have the same item
S.issubset (t) returns True if S is a subset of T
S.issuperset (t) returns True if S is a superset of T
S.symmetric_difference (t) to find the symmetric difference set, return the item in s or T, but not in both sets
s.union (t) to return an item in S or T.
Collection operations
s | T----The set of S and T
The intersection of S & T----s and T
S-T---- seek the intersection
s^ t---- symmetry intersection
Len (s)----The number of items in the collection
Max (s)---- maximum value
MIN (s)---- minimum value
S1.add (' Lai ') can take a string as an entire set of elements
This article is from the "A-filled blog" blog, please be sure to keep this source http://laizetian.blog.51cto.com/10728827/1698761
Data types for Python