Variable type conversion
Function:
to splice different types of data together.
Example: str and int cannot be connected by + (connector), and need to convert int to str
conversion type function:
- str (other types) is
converted to a string - 'Other types' are
converted to strings - Int (non-literal and decimal strings) is
converted to integers and the
decimal part is wiped out - Float (non-literal string) is
converted to decimal and the
decimal part is filled with zeros
Boolean type is automatically converted to integer
v=123
print('字符串'+str(v))
v='123'
print(1+int(v))
v='1.2'
print(1+float(v))