python learning 4 (variable type conversion)

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:

  1. str (other types) is
    converted to a string
  2. 'Other types' are
    converted to strings
  3. Int (non-literal and decimal strings) is
    converted to integers and the
    decimal part is wiped out
  4. 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))

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40551957/article/details/113738440