鱼C论坛

 找回密码
 立即注册
查看: 509|回复: 2

[已解决]萌新初学问题

[复制链接]
发表于 2018-8-24 19:08:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
_hello=4
yes4_=5
yes_4=6
print(_hello,yes4_,yes_4,end='')
print('hello world'+' python'*5)

输出结果是
4 5 6hello world python python python python python

疑惑1,print()变量之间的逗号=空格的作用么
2,6hello 中间怎么加空格 是在hello前面打一个TAB么,以及我怎么在6hello之间输出结果加一个逗号‘,’
最佳答案
2018-8-24 19:23:38
本帖最后由 claws0n 于 2018-8-24 19:32 编辑

end = ' ' 是让打印的结果后面接上空格(' ')。因此第二个 print() 不会在另一行打印
加 tab (\t) 就太大了,print(' hello world'),在 h 前面加空格就可以了
但正确来说应该是 end = ' '   中间是有空格的
  1. _hello=4
  2. yes4_=5
  3. yes_4=6
  4. print(_hello,yes4_,yes_4,end=' ')
  5. print('hello world'+' python'*5)
复制代码


补充:
不全然,逗号是把不同的参数/你想要打印的结果分开,只是在打印时会自动加上空格,让你可以辨识
print(123+'string') 是不能通过的,因为数据类型不一样。但是
print(123,'string')  >> 123 'string'
print(str(123)+'string')  >> 123string
print(str(123)+' string')  >> 123 string
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-8-24 19:23:38 | 显示全部楼层    本楼为最佳答案   
本帖最后由 claws0n 于 2018-8-24 19:32 编辑

end = ' ' 是让打印的结果后面接上空格(' ')。因此第二个 print() 不会在另一行打印
加 tab (\t) 就太大了,print(' hello world'),在 h 前面加空格就可以了
但正确来说应该是 end = ' '   中间是有空格的
  1. _hello=4
  2. yes4_=5
  3. yes_4=6
  4. print(_hello,yes4_,yes_4,end=' ')
  5. print('hello world'+' python'*5)
复制代码


补充:
不全然,逗号是把不同的参数/你想要打印的结果分开,只是在打印时会自动加上空格,让你可以辨识
print(123+'string') 是不能通过的,因为数据类型不一样。但是
print(123,'string')  >> 123 'string'
print(str(123)+'string')  >> 123string
print(str(123)+' string')  >> 123 string

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +3 收起 理由
xzx1 + 5 + 5 + 3 谢谢版主大大的详细解答,初学者问题可能比.

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-24 19:26:09 From FishC Mobile | 显示全部楼层
1,应该可以这么说吧,
2,在hello前面加空格或者逗号即可
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-5 13:57

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表