A primer
1 What is data?
x=10,10 is the data we want to store.
2 Why data is divided into different types
Data is used to represent States, and different States should be represented by different types of data.
3 Data types
Numbers (shaping, long-shaped, floating-point, plural)
String
BYTE string: Describes the byte bytes type when introducing character encoding
List
Meta-group
Dictionary
Collection
4 Expand Data Type learning by following several points
#一: Basic use 1 Purpose 2 definition way 3 common operation + built-in method # Two: The type Summary 1 to save a value or save multiple values can be stored in a value of multiple values, the value can be what type 2 ordered or unordered 3 variable or immutable!!! Variable: The value changes, the ID does not change. Variable = not hash!!! Immutable: The value changes, and the ID is changed. immutable = = can be hashed
Two numbers
Integral type and floating point type
#整型int role: Age, grade, social Security number, QQ number and other integer-related definitions: age=10 #本质age =int (Ten) #浮点型float role: salary, height, weight, physical parameters and other floating point salary=3000.3 #本质salary =float (3000.3) #二进制, decimal, octal, hex
Three strings
Name= values by index (positive fetch +
Four list
my_girl_friends=[,,, 4,5] =list (Access value by index (forward Access +
#ps: Reverse Step l=[1,2,3,4,5,6] #正向步长l [0:3:1] #[1, 2, 3] #反向步长l [2::-1] #[3, 2, 1] #列表翻转l [::-1] #[6, 5, 4, 3, 2, 1]
Five tuples
#作用: To save multiple values, the tuple is immutable (a key that can be used as a dictionary) in comparison to the list, primarily to read the # definition: Compared to a list type, except for [] age= (11,22,33,44,55) Nature age=tuple (11,22,33,44,55) #优先掌握的操作: Value by index (positive fetch + reverse): only slices (Gu Tou regardless of tail, step) length member operation in and not in loop
Six dictionaries
#作用: Save multiple values, Key-value access, fast value # Definition: Key must be immutable type, value can be any type info={' name ': ' Egon ', ' age ': ', ' sex ': ' Male '} #本质info =dict ({ ....}) or Info=dict (name= ' Egon ', age=18,sex= ' male ') or info=dict ([[' Name ', ' Egon '], (' age ', 18)]) or {}.fromkeys (' name ', ' age ', ' Sex '), None) #优先掌握的操作: Access Value by key: The available length Len member operation in and not in Delete key (), value values (), key value pair items () loop
Seven sets
# Role: de-weight, relational operations, #定义: Knowledge points review mutable types are non-hash types immutable type is a hash type # definition set: collection: Can contain multiple elements, separated by commas, The elements of a collection follow three principles: 1: Each element must be an immutable type (hash , can be used as a dictionary key) 2: No duplicate elements 3: The purpose of a disorderly attention set is to store different values together, and to do relational operations between different sets. No need to tangle with a single value in the collection #优先掌握的操作: Len member operation in and not in| collection & intersection-difference Set ^ symmetric difference set ==>,>= ,<,<= parent set, subset
Eight data Type Summary
Sub-footprint (low to high) per storage space
Numeric string collection: unordered, that is, unordered storage index related information tuple: ordered, need to store index related information, immutable list: Orderly, need to store index related information, variable, need to deal with the data to change the dictionary: unordered, need to save key and value mapping information, variable, need to deal with data deletion and modification
Differentiate by number of stored values
Scalar/Atomic Type |
Number, string |
Container type |
list, tuple, dictionary |
By Variable immutable distinction
Variable |
List, dictionary |
Not variable |
Numbers, strings, tuples |
Differentiate by Access order
direct access to |
number |
sequential access (sequence type) |
String, list, tuple |
key Value access (mapping type) |
Dictionary |
Back to Top
Nine operators
#身份运算 (IS, isn't) is the ID, while the double equals is the value of the same, the ID is the same, and the same value is the same ID >>> x=1234567890>>> y=1234567890 >>> x = = ytrue>>> ID (x), id (y) (3581040, 31550448) >>> x is Yfalse
Python Day 2 data type, character encoding, file processing