Data type conversion
Note
# Str = input ( 'Please enter your words:')
Comment effects: 1. 2. marked explain exclusion errors
Single-line comments: shortcut is shift + #
Multi-line comments: ctrl +?
py file Run: 1.shift + 10 2. Right-click ----> Run button on the Run 3. Run column
variable
i=8
Variable names relationship with the variable value :
1. A variable name can correspond to a variable value, a variable value may correspond to a plurality of variable names.
2. The same variable name, a new variable value replaces the old variable values
Variable naming convention:
1. The variable name can not use Chinese, English is recommended not to use the alphabet.
2. Variable names can use numbers, but not as the beginning
3. The variable name can only be used with special symbols _
4. Variable names strictly case-sensitive.
The variable names to be meaningful (ie, specification, it is best to let others could quickly be able to understand)
6. Variable names can not conflict with reserved keywords.
View reserved keyword:
import keyword
print(keyword.kwlist)
Six types of data (priority)
NUM (numeric): comprising int (integer), a float (float, i.e. decimals), BOOL (Boolean, only True and False), complex (complex, Real + Imaginary)
str (string): declared methods are: 1 '' 2 '' 3 '' '' '' 4 "" "" ""
list (list type): which can put multiple values, but use commas to separate
tuple (tuple type): There is a comma-tuple brackets, no comma is what the type is what type
set (set of): a disorder, of the de-emphasis.
dict (dictionary): present in the form of key-value pairs
Six data type classification:
According to whether the container Category:
Container type: str, list, tuple, set, dict
Non-container type: num
To be changed according to whether TYPE:
Type can not be changed: num, str, tuple
Type can be changed: list, set, dict
Data types of glyphs:
str:‘’ list:[] tuple:(,) set:无 dict:{}
Data type conversion (priority):
Can be converted to an int are: float, bool, str (can be numeric)
Can be converted into float are: int, bool, str (can be numeric)
Bool can be converted into are: int, float, complex, str, list, tuple, set, dict
Can be converted into a complex are: int, float, bool, str (can be numeric)
Can be converted into str are: any data type can be converted into str
Can be converted into list are: str, tuple, set, dict
Can be converted into tuple are: str, list, set, dict
Can be converted into a set are: str, list, tuple, dict
There can be converted into a dict: str, list, tuple, set