日常写Bug——Python3打印完数据后不换行

来源:互联网 发布:下颌第一磨牙雕刻数据 编辑:程序博客网 时间:2024/06/05 11:31

最近用python实现数据结构中某些算法时发现,python3的打印后会自动换行,这样的话看起来就很不方便

其实print函数有个end参数,而默认的end参数为’\n’换行符

不要默认换行只需要把end参数设置为’ ‘就行了

如:

def print_data(data):    for i in data:        print(i,end=' ')    print()

附:python3 print基本操作

格式化输出:

s='hello'x=len(s)print("The length of %s is %d" % (s,x))  

结果为: The length of Hello is 5

拼接字符串:

x='Hello'y='World'print(x+y)

结果为: ‘HelloWorld’

原创粉丝点击