Python2中这样写:
print "welcome to china!"
python3中要这样写:
print ("welcome to china!")
实现加减乘除:
python2中这样写:
#from pip._vendor.distlib.compat import raw_input
a = input("please input first number:")
b = input("please input second number:")
print("a+b=",a+b)
print("a-b=",a-b)
print("a*b=",a*b)
print("a/b=",a/b)
python3中这样写:
from pip._vendor.distlib.compat import raw_input
a = int(raw_input("please input first number:"))b = int(raw_input("please input second number:"))
print("a+b=",a+b)
print("a-b=",a-b)
print("a*b=",a*b)
print("a/b=",a/b)
若不加from pip._vendor.distlib.compat import raw_input,则
会出现错误:
TypeError: unsupported operand type(s) for -: 'str' and 'str'