#变量数据类型,整数integer
num = 1
#变量数据类型,字符串string
string = '1'
#不同数据类型无法合并
print(num + string)
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
Traceback (most recent call last):
File "c:/Users/harveymei/hello.py", line 6, in <module>
print(num + string)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
PS C:\Users\harveymei>
#变量数据类型,整数integer
num = 1
#变量数据类型,字符串string
string = '1'
#转换数据类型
num2 = int(string)
print(num + num2)
PS C:\Users\harveymei> & C:/Users/harveymei/AppData/Local/Programs/Python/Python38/python.exe c:/Users/harveymei/hello.py
2
PS C:\Users\harveymei>