python超级简单的类型转换


a = int(raw_input("请输入一个整数"))
print("你输入的是:"+str(a))

如果a想要拼接,但是不进行类型转换那么是如下错误:

raceback (most recent call last):
  File "/Users/aaa/PycharmProjects/myphton/demo.py", line 12, in 
    print("你输入的是:"+a)
TypeError: cannot concatenate 'str' and 'int' objects

Process finished with exit code 1

你可能感兴趣的:(python超级简单的类型转换)