end和sep的使用方法

end: 默认是换行'\n',表示以什么结尾,比如以, | \n 等
方法:

默认end = '\n'
a
b
c
如果end = ' '
a b c

sep: 默认是空格' ' 表示两个字符之间用什么隔开,如, : |等
方法:

sep = ','
老板,root,12

sep = '|'
老板|root|12

说实话以上也看不出什么来.二者效果区别如下:

sep = '|'
name = input('name:')
age = input('age:')
print(name,age,sep='|')
输出结果:
name:root
age:123
root|123 # 看我

end = '|'
name = input('name:')
age = input('age:')
print(name,age,end='|')
输出结果:
name:root
age:123
root 123| #看我

猜你喜欢

转载自www.cnblogs.com/zanao/p/10990071.html
今日推荐