the python operator
1. Arithmetic operation:
2. Comparison operation:
3. Assignment Operation:
4. Logical Operation:
5. Member Arithmetic:
Basic data types for Python
1. Digital
int (integral type)
On a 32-bit machine, the number of integers is 32 bits and the value range is -2**31~2**31-1, which is -2147483648~2147483647
On a 64-bit system, the number of integers is 64 bits and the value range is -2**63~2**63-1, which is -9223372036854775808~9223372036854775807
2. Boolean valueTrue or False 1 or 0
3. String
"Hello World"
String Common functions:
- Remove blank strip (self, Chars=none)
- Split Partition (self, SEP)
- Length __len__ (self)
- Index []
- Slice [:]
4. ListTo create a list:
123 |
name_list = [ ‘alex‘ , ‘seven‘ , ‘eric‘ ] 或 name_list = list ([ ‘alex‘ , ‘seven‘ , ‘eric‘ ]) |
Basic operation:
- Index []
- Slice [:]
- Append Append (self, p_object)
- Delete Remove (self, value)
- Length Len
- Loop for
- Contains
5, GansoTo create a meta-ancestor:
123 |
ages
=
(
11
,
22
,
33
,
44
,
55
)
或
ages
=
tuple
((
11
,
22
,
33
,
44
,
55
))
|
Basic operation:
- Index []
- Slice [:]
- Loop for
- Length Len
- Contains
6. Dictionary (unordered)To create a dictionary:
123 |
person = < Code class= "Python plain" >{ : "Mr.wu" , ' age ' : 18 or person = dict "Mr.wu" , : 18 |
Common operations:
- Index [key]
- Added [Key1]=value
- Delete Clear
- Key, value, key-value pair Keys,values,viewitems
- Loop default Loop key
- Length Len
PS: Loops, range,continue and break other
1. For LoopThe user iterates through the contents of an object in order, Ps:break, continue
123 |
li = [ 11 , 22 , 33 , 44 ] for item in li: print item |
2, EnumrateAdd an ordinal to an object that can be iterated
123 |
li = [ 11 , 22 , 33 ] for k,v in enumerate (li, 1 ): print (k,v) |
3. Range and XrangeSpecify a range to generate the specified number
12345678 |
print
range
(
1
,
10
)
# 结果:[1, 2, 3, 4, 5, 6, 7, 8, 9]
print
range
(
1
,
10
,
2
)
# 结果:[1, 3, 5, 7, 9]
print
range
(
30
,
0
,
-
2
)
# 结果:[30, 28, 26, 24, 22, 20, 18, 16, 14, 12, 10, 8, 6, 4, 2]
|
Python lesson two, operators and basic data types