如何使用Python中的匹配检查两个变量值?

发布于 2025-02-09 01:21:18 字数 195 浏览 1 评论 0原文

变量的检查值的一种方法是使用一个或两个匹配块,但是如何使用一个匹配块检查值,并检查变量值在python中与匹配块中的范围内,例如此代码:

somevalue=int(input("enter any number"))
if 10<somevalue<1000:
    print("some message")

one way for check value of a variable is to use if or two match block but how to check the value with one match block and also check variable value to be in a range in python with match block, for example this code:

somevalue=int(input("enter any number"))
if 10<somevalue<1000:
    print("some message")

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

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

发布评论

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

评论(2

静水深流 2025-02-16 01:21:18

我认为此代码是您编写的block的一个很好的选择。

numbers=list(range(11,1000))
match somevalue:
    case numbers:
        print("some value")

这是您想要的吗?

I think this code is a good alternative to if block that you've written.

numbers=list(range(11,1000))
match somevalue:
    case numbers:
        print("some value")

Is this something you were looking for?

一个人的夜不怕黑 2025-02-16 01:21:18

这样的东西?匹配案例语句并不是要做这种类型的事情。

match 10 < int(input("enter any number")) < 1000:
    case True:
        print('some message')

您想要的另一个可能性可能是:

somevalue = int(input("enter any number"))
if somevalue > 10 and somevalue < 1000:
    print('some message')

Something like this? Match-case statements aren't really meant to do this type of thing.

match 10 < int(input("enter any number")) < 1000:
    case True:
        print('some message')

Another possibility of what you're asking for could be:

somevalue = int(input("enter any number"))
if somevalue > 10 and somevalue < 1000:
    print('some message')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文