您的位置:首页 > 编程语言 > Python开发

python print

2015-06-01 15:42 609 查看
>>> help(print)
Help on built-in function print in module builtins:

print(...)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.
# 输出结果是有引号的
>>> 'Python'
'Python'
# 输出结果没有引号
>>> print('Python')
Python

>>> 5 + 8
13
>>> 8/4
2.0
>>> 8//4            # 如果想要输出整数,需要用两个除号“//”
2
>>> 8*8
64
>>> print(8//2)
4
字符串拼接

>>> 'I'+' '+'LOVE'+' '+'PYTHON'+' '+'!'
'I LOVE PYTHON !'
>>> 'I LOVE PYTHON !'
'I LOVE PYTHON !'
>>> 'I LOVE PYTHON ! ' * 3
'I LOVE PYTHON ! I LOVE PYTHON ! I LOVE PYTHON ! '


>>> print('line1','line2',sep="\n")
line1
line2
>>> print('line1','line2',sep='\n\n')
line1

line2
>>> print('line1',end="\n");print('line2')
line1
line2
>>> print('line1',end="-------不让换行------");print('line2')
line1-------不让换行------line2


<> I love "python" !
print("I love \"python\"!")
print('I love "python"!')


在IDLE中输入"print('python')",按F5执行,可得到以下结果。
>>> ================================ RESTART ================================
>>>
python
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: