在 Python Idle 中突出显示文本
所以我正在修改我的代码,我希望我可以突出显示我犯错误的部分,这样如果我回到它并从中学习,就很容易发现错误......
#Don't Need True When Using In
gifts = []
l = input ("What do you want to have?")
gifts.append(l)
while l.lower() != "nothing" :
l = input ("Anything else?").lower()
gifts.append(l)
a = gifts.index("nothing")
gifts = gifts[:a] + gifts[a+1:]
if "soup" in gifts ==True:
b = gifts.index('soup')
gifts = gifts[:b]+["broth"]+gifts[b+1:]
for x in gifts:
print ("I can give you", end= " ")
print (x, end = " ")
print ("if you wish..")
我把它困在了一个三重引号来保存它,所以现在一切都是绿色的。我可以以某种方式只将(如果礼物中的“汤”== True:) 部分变成不同的颜色吗?
So I'm revising my code and I'm wishing I could highlight just the part where I made a mistake so it would be easy to spot the mistake if I come back to it and learn from it....
#Don't Need True When Using In
gifts = []
l = input ("What do you want to have?")
gifts.append(l)
while l.lower() != "nothing" :
l = input ("Anything else?").lower()
gifts.append(l)
a = gifts.index("nothing")
gifts = gifts[:a] + gifts[a+1:]
if "soup" in gifts ==True:
b = gifts.index('soup')
gifts = gifts[:b]+["broth"]+gifts[b+1:]
for x in gifts:
print ("I can give you", end= " ")
print (x, end = " ")
print ("if you wish..")
I trapped it in a triple quote to preserve it so everything is green right now. Can I make just the (if "soup" in gifts == True:) part a different color somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,您不能,但另一个解决方案是写
一个
# TODO - fix stuff on the left --------------------------------
在这条线的右侧发表评论
From what i know you can't, but another solution would be to write
a
# TODO - fix stuff on the left --------------------------------
comment on the right side of this line