Python: print()格式

参考print的官方文档

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.

 >>> s = 'k'
>>> k = 'e'
>>> print(s+k)
ke
>>> print(s,k)
k e
两个变量之间默认使用空格隔开

打印字符串:

def review():
    t = int(input())
    for i in range(t):
        s = input()
        print(s[::2], s[1::2])

s[i:j:k]默认i=0,j不输入默认到最后一位, k=1

猜你喜欢

转载自blog.csdn.net/lcqin111/article/details/82155329