2017-06-24 14:34:39
1, integers and long integers
2. Floating point number
3, plural, shape such as 1+4j, etc.
4, string single quotation marks can be, there are three quotation marks, the function of three quotation marks to achieve the operation of multi-line string
Common functions:
Len (): Gets the length of the string
5. List
Hit the array of hormones, compared to the C + + array, the list is more powerful, no data type, can be put in. The list is a mutable data type, such as: a=[0,1,2,3]
Access elements and arrays consistent, list[0] ..., the subscript value can be negative, list[-1] represents the last number, list[:] Represents a copy of the whole, list[:-1] represents the slice except the last number
At the same time can be sliced list[0:3], is still the front open after closed, that is, only 0,1,2, similar to MATLAB
You can use the for item in list: to traverse the list
A list is a sequence
Common functions:
. Len (): List length
. Append (): Add an element at the end
. Extend (): parameter type is a list, add multiple elements at the end
. Insert (Pos,key): Add key at POS location
. Remove (key): Delete the first key
Del list[0]: You can delete the entire list by following the subscript
6, tuple tuple
Ganso and lists are very similar, but the progenitor is immutable
Ganso General representation is a= (all-in-one), the comma is the root of the identity tuple, and if you remove (), its data type remains a tuple
Elements of tuples cannot be modified or deleted.
Empty tuple a= ()
A= (1,) with only one element, comma essential
One example of a specific use of tuples is the print function
" Timhy " =print("age of%s is%d" % (name,age))
A tuple is a sequence
7. Dictionary Dict
Similar to the map in the STL, the use of the Key,value storage form, the specific form: a={' A ' =1, ' B ' =2, ' c ' = 3}
The addition of dictionaries is also the same as map, i.e. a[' d ']=4
The deletion of the dictionary is the same as list, using the index value to complete the delete operation, Del a[' a ']
You can use the for Aipha,number in A.items (): To complete the traversal
Some of the other built-in functions:
Type (): Used to determine the type of variable
Isinstance () Function: Judging data type
Isinstance (520,int) gets True
Python Data structure