
正文
包含python输出函数是的词条
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
python中函数输出怎么使用
print函数是python语言中的一个输出函数,可以输出以下几种内容
1. 字符串和数值类型 可以直接输出
print( 1)
1
print( "Hello World")
Hello World
2.变量
无论什么类型,数值,布尔,列表,字典...都可以直接输出
x = 12
print(x)
12
s = 'Hello'
print(s)
Hello
L = [ 1, 2, 'a']
print(L)
[ 1, 2, 'a']
t = ( 1, 2, 'a')
print(t)
( 1, 2, 'a')
d = { 'a': 1, 'b': 2}
print(d)
{ 'a': 1, 'b': 2}
3.格式化输出
类似于C中的 printf
s
'Hello'
x = len(s)
print( "The length of %s is %d" % (s,x) )
The length of Hello is 5
【注意】
Python2和3的print函数格式不同,3要求加括号(print())
缩进最好使用4个空格
相关问答
Q1: 在python中,数据的输出用哪个函数名
Python3中使用:print()函数
用法(从IDLE帮助上复制):
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.
value即你要输出的值(大多数类型均可),sep是这多个值用什么分割(默认为空格),end是这个输出的末尾是什么(默认是换行)。
Q2: Python编程时能在显示器上输出信息的函数是?
pint()函数,是python中屏幕输出用的。
如:
a = "test"
print(a)
print("test")
print("this", "is", "a", "test", "!")
print("this " + "is " + "a " + "test " + "!")
如有帮助,请采纳!!!






