在 Python Idle 中突出显示文本

发布于 2025-01-18 20:18:28 字数 685 浏览 4 评论 0原文

所以我正在修改我的代码,我希望我可以突出显示我犯错误的部分,这样如果我回到它并从中学习,就很容易发现错误......

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流心雨 2025-01-25 20:18:28

据我所知,您不能,但另一个解决方案是写
一个
# 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文