print 字符串和print 字符串叠加
print(1)
1>>> print('hellow world and hql')
hellow world and hql
>>> print("hello world and hql")
hello world and hql
>>> print ('hello world'+" "+'hello world hql')
hello world hello world hql
简单运算:
2
>>> print(8-2)
6
>>> print(3*4)
12
>>> print(12/4)
3.0
>>> print(5+"hql") # 字符串不可以直接和数字相加
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
print(5+"hql") # 字符串不可以直接和数字相加
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> print(int('2'+3))
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
print(int('2'+3))
TypeError: must be str, not int
>>> print(int('3')+2)
5
>>> print(int(2.4)) # 当int一个浮点型数时,int会保留整数部分
2
>>> print(float('5.4')+3) # float()是浮点型,可以把字符串转换成小数
8.4
>>>