python的print 功能

来源:互联网 发布:逐点比较圆弧插补算法c 编辑:程序博客网 时间:2024/06/05 15:53

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

简单运算:

>>> print (1+1)
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
>>>
0 0
原创粉丝点击