qingsi 发表于 2022-3-6 23:05:26

去除运行结果里的空格

= 1
c = 3
v = 4
print(x,c,v)
运行结果为
1 3 4
如何变成
134

isdkz 发表于 2022-3-6 23:06:54

本帖最后由 isdkz 于 2022-3-6 23:09 编辑

>>> 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.

>>>

从 print 的文档可以看出,print 函数有个关键字参数 sep,是用来作 print 的参数的间隔符的,

而 sep 的默认值为 空格,你把 sep 赋值为 空 就可以把空格去掉了
print(x,c,v, sep='')
页: [1]
查看完整版本: 去除运行结果里的空格