A: Number The number types (int float bool complex)
1. Integer: (a positive integer 0 negative integer)
# (1) 0b represents a binary
IntVar = 0b1010
Print (IntVar)
Print (type (IntVar)) # Get IntVar type
print (id (intvar)) # 16 is acquired into prepared
#type type variable can be acquired
#id that can obtain the address value of the variable points
a =. 5
# represented by octal 0o
IntVar = 0o127
Print (IntVar)
Print (type (IntVar))
Print (ID (IntVar) )
(hexadecimal) is represented by 0x
IntVar = 0xFF
Print (IntVar) # converted to decimal number 2
Print (type (IntVar))
Print (ID (IntVar))
IntVar = 0
Print (IntVar, type (IntVar ))
intar = 0
Print (IntVar, type (IntVar))
2. a float float (decimal type)
# indicates a method
floatvar = 3.14
Print (floatvar, type (floatvar), ID (floatvar))
# Representation bis (scientific notation)
floatvar = 5.88e-2
Print (floatvar, type (floatvar), ID (floatvar))
floatvar = 4.11e3
Print (floatvar)
3.bool Boolean type (only two states Ture or False )
boolvar = True
Print (boolvar, type (boolvar), ID (boolvar))
boolvar = False
Print (boolvar, type (boolvar), ID (boolvar))
4.complex complex type
'' '
complex: real + imaginary
J: If there is a number that is equal to the square -1, j is the number of
scientists believe that there is, high-precision type is
''
# representation of a
complexvar = + 3j. 4
Print (complexvar, type (complexvar), ID (complexvar ))
# representation two
#complex (real part, imaginary part)
complexvar = Complex (. 8, -3)
Print (complexvar, type (complexvar), ID (complexvar))
Two: String string type
Definition: quotes is a string
Escape character:
(1) becomes meaningless characters interesting
(2) becomes meaningless characters meaningful
syntax: \ + a character
\ n \ r \ n: Representative wrap
\ T: represents an indent level tab
\ r: pull the strings behind the current line
\
'' '
# (1) single quotation marks string
strvar =' nice day '
Print (strvar, of the type (strvar), the above mentioned id ( strvar))
# (2) double-quoted string
starvar = "goes in cycles DF"
Print (starvar, type (starvar), ID (starvar))
starvar1 = "small building 'Zala'" # outside is bis quotes, which require a single quote nesting annotations same attention point
Print (starvar1, type (starvar1), ID (starvar1))
# usage newline
starvar2 = "homeland painful \ n moon in"
Print (starvar2, type (starvar2 ), the above mentioned id (starvar2))
# \ usage
starvar3 = "return to the motherland bear \" first \ "the moon"
Print (starvar3)
# (. 3) three-quoted string
strvar = "" "
Had not a 'product',
Where provoke "dust" Egypt.
"" "
Print (strvar)
strvar1 = '' '
ha ha
oooo
' ''
Print (strvar1)
# (. 4) membered string r" string "(which allows escape character string failure)
starvar5 = r "the weather today is nice \ n ha"
Print (starvar5)
# (. 5) format string
"" "
% D: integer placeholder
% f: float placeholder
% s: string representing placeholder
syntax: "placeholder character string"% (actual value)
syntax: string% (value 1, value 2, .... value. 3)
"" "
#% d
starvar6 =" bought today are% d basin "% (5)
Print (starvar6)
two default position #% 2d station right home
strvar7 ="% 2d pounds yesterday to buy fruit "% (5)
Print (strvar7)
#% -2d station two positions, default left
strvar8 = "% -2d bought a barrel today."
Print (strvar9)
# set to retain two
strvar10 = "today pay much .2f%"% (9.99)
Print (strvar10)
# set to retain a precise number of digits when the provisions of rounding
strvar11 = "Today pay how much .1f% "% (9.99)
Print (strvar11)
#% S
AA =" Ten "
strvar12 ="% S "% (AA)
Print (strvar12)
# integrated case
strvar13 =" who opened wages, a total of% d yuan ,% d dollars a car, mood% s "% (12900,21313," very good ")
Print (strvar13)
'' 'Wherein: unmodifiable can get ordered' ''
# string-elements can be acquired using the subscript
tuplevar = "our class only a beautiful"
RES tuplevar = [-2]
Print (RES)
# modify okay? No
#tuplevar [-2] = "Liang" error
Three: List List Type
- Define an empty list
'' ' wherein: available modifiable ordered ' ''
listvar = []
Print (listvar)
Print (type (listvar))
# 0. 5. 4. 3. 1 2 Forward subscript
listvar = [ "Tomorrow" , 2,3.14, True, False, 3-2j]
# -6 -5 -4 -3 -2 -1 subscript reverse
Print (listvar)
# (. 1) obtain a list of values corresponding to the acquired index
res = listvar [. 3]
Print (RES)
# can be obtained through reverse list index inside the last instantaneous value
#res <==> Result
RES = listvar [-1]
Print (RES)
# value by obtaining a list of the last approach
#len Get length of the list (number of elements)
lengthvar = len (listvar)
Print (lengthvar)
RES2 = lengthvar -. 1
Print (RES2)
Print (listvar [RES2])
# shorthand
Print (listvar [len (listvar) -1])
# (2) to modify the list
listvar [. 3] = "201 904 251 725"
Print (listvar)
four: Tuple tuple type
'' ' Wherein: available unmodifiable ordered ' ''
1. define an empty tuples
tuplevar = ()
Print (tuplevar, type (tuplevar))
# witness is not a tuple, depending on the comma, but the tuple space declarations may be used ()
tuplevar = ( "One")
Print (tuplevar, type (tuplevar))
2. acquires data tuple
tuplevar = ( "Andy", "Chow", "Li", "ocean")
Print ( tuplevar)
Print (tuplevar [2])
Print (tuplevar [-1])
# whether to change the values in the tuple? Allowed
#tuplevar [0] = 1 error
Five: the Set collection type
# Set of action: Set intersection and complement difference set (function is used to do intersect and complement)
'' ''
wherein; automatically go to infinite weight
'' '
1. Define an empty set
setvar = set () #set cast type of data into an empty set
Print (setvar, type (setvar))
setvar = { "Andy" "Choi", "Li", "ocean"}
Print (setvar)
2. set can not obtain or modify data therein
# can I get a set of values among? No
#setvar [1] error
value # if the collection can be modified among? No
#setvar error = 123
3. set to automatically re
setvar = { "Andy" "Choi", "Li", "ocean", "Li"}
Print (setvar)
Six: Dict dictionaries
'' 'Feature: key data on storage disorder' ''
# Dictionary 3.6 version looks orderly and disorderly in nature, because the underlying hash algorithm used, it stores data hash.
1. Define an empty dictionary
dictvar} = {
Print (dictvar, type (dictvar))
# which is stored in the key data, the key is the left of the colon, the right is the key-value pair separated by commas
= {dictvar "Top" : "Guan" , "Middle" : "Joe" , "bottom" : "descent" , "Jungle" : "blind monk" , "Support" : "robot" }
Print (dictvar)
2 get value among the dictionary
RES = dictvar [ "bottom"
"Wang Zhaojun"
Print (dictvar)
"" "
may be hashed data:
hashable data (immutable data): Number (int float bool comple ) str tuple
not hashed data (variable data): list set dict
"" "
dictvar = {. 1: 111,3.14: 222, False : 232,3 +. 4J: 131 321, " Dada " : 666}
Print (dictvar) # dictionary contains various other data types
# general dictionary named when the key is recommended to use strings, according to a string variable named
Dictionary, a collection of hash algorithm to note
```
Hash Algorithm
definition:
The length of any value is calculated as the immutable fixed length unique value, this value can be positive or negative, can be very flexible, but fixed length
The algorithm called a hash algorithm, the fixed length value called the hash value
Features:
When hash over the data storage, is a random stored hash is not stored sequentially in the order,
So the speed by hashing algorithm to store data faster.
Find:
Dictionary key is calculated according to the hash algorithm can find the corresponding value by the hash key, the mapping relationship is formed
Set of values is calculated by a hash algorithm stored after
So a collection of unordered dictionary on nature
version:
Prior to version 3.6 are out of order
After the 3.6 version of the dictionary literal order record, when to get data from memory,
According to literally re-ordered, so it looks like the order, but in essence disorder
Hashable data:
The data may be hashed (immutable data): Number (int float bool complex) str tuple
Not be hashed data (variable data): list set dict
```