Python basic data type (0717)
1. Numbers:
Integer int: For example: grade, age, rank, etc.
float: Price, etc. (when using decimals)
2. String str:
Purpose: Descriptive data,
Value: string is a whole
The portion of a string that can be taken with an index or slice
string concatenation:
' String1 ' + ' string ' or string*3
3. List of lists
contained within [], each element separated by commas
Purpose: There are multiple values that can be modified for each element
Method:
List.append () #在尾部增加一个元素
List.remove () #删除指定的元素
Operation:
1. View, use the index;
2. Increase List.append ()
3. Delete the index of the List.remove (element) or del list[element]
4. Modify list[Index] = value
4. Dictionary Dict
Defined within {}, comma separated, each element in the form of Key:value
Dictionary:
Purpose: To store multiple values, similar to the list, the value can be any data type, key is immutable type;
Operation:
View: Dict[key] View the corresponding value
Added: Dict[key] = value
Delete: Del Dict[key]
Modified: Dict[key] = value (new value)
5. Boolean type True False
Purpose: Used to judge
For example:
If num > 50:
Print (' Hello World ')
Else
Print (' Wow ... ... ')
Not to be continued
Basic data types for Python first knowledge