为什么 input 不使用 .lower() 或 .upper() 命令返回打印值?

发布于 2025-01-15 20:54:08 字数 1469 浏览 2 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

勿忘初心 2025-01-22 20:54:08

在这行代码中:

Good = input('Am i Good? > ').upper()

您将输入转换为大写,然后将该字符串与小写字符串进行比较(“no”“quit”)。这永远不会匹配,因为 "NO""no" 是不同的字符串(Python 在比较字符串时关心大小写)。

In this line of code:

Good = input('Am i Good? > ').upper()

You transform the input to uppercase, but then you compare the string with lowercase strings ("no", "quit"). This will never match since "NO" and "no" are different strings (Python cares about case when comparing strings).

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