鱼C论坛

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

[已解决]小白问题,研究半天没明白

[复制链接]
发表于 2018-1-9 22:51:34 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 13194608570 于 2018-1-9 22:54 编辑

原帖代码.png
这是自己求虐找的习题。。。初级中的初级,请不要笑话我。。。
# A comment,this is so you can read your program later.
# Anything after the # is ignored by ptthon.
print("I could have code like this."# and the comment after is ignored)
#you can also use a comment to "disable" or comment out a piece of code:
#print("This won\'t run.")
print("this will run.")
以上是我自己打的代码,但是在CMD下运行报错
报错.png
核对了很多遍找不到问题原因出在哪,我知道第一张图的代码是python2的代码,但是我加上了()还是不行



问题已经找到了,是因为print("I could have code like this."# and the comment after is ignored)的括号把#后边的解释句子括进去了,但是为什么括进去会出错,是因为#这个符号么?
最佳答案
2018-1-9 22:59:52
print的参数可以是数字,也可以是字符串,你的程序中print("I could have code like this."# and the comment after is ignored)
前半部分是字符串,后面跟的就无法判断是什么了,这与#无关。例如
print('asd'fg)也是错的。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-1-9 22:59:52 | 显示全部楼层    本楼为最佳答案   
print的参数可以是数字,也可以是字符串,你的程序中print("I could have code like this."# and the comment after is ignored)
前半部分是字符串,后面跟的就无法判断是什么了,这与#无关。例如
print('asd'fg)也是错的。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-9 23:06:51 | 显示全部楼层
冬雪雪冬 发表于 2018-1-9 22:59
print的参数可以是数字,也可以是字符串,你的程序中print("I could have code like this."# and the comme ...

感谢,我明白您的意思了,谢谢~~
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-5 17:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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