Scala also has "match" cases that are Class redefinable, used for regex for
example
About integers ranges, we already have the master class : builtins.range
pip install funcoperators deals with the issue like this :
for i in 1 /irange/ 5:
print(i) # will print 1 2 3 4 5
Where irange = infix(lambda a,b: range(a, 1+b))
About matching, switch case does not exist in python because if/elif/else
cascade exists
if (x := 5) in irange(1, 5):
println(stuff1)
elif x == 8
println(stuff2)
else:
println(stuff3)
and with factorization :
print(stuff1 if (x := 5) in irange(1, 5) else
stuff2 if x == 8 else
stuff3)
Le mer. 12 mai 2021 à 21:41, Valentin Dymchishin <[email protected]>
a écrit :
> Hi everyone!
> I've just read about pattern matching in Python 3.10, and it sounds really
> nice.
> I've also found out that Rust supports ranges in pattern matching.
>
>
> https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html#matching-ranges-of-values-with-
>
> fn main() {
> let x = 5;
> match x {
> 1..=5 => println!("one through five"),
> _ => println!("something else"),
> }
> }
>
> Can we have something similar please? I think this would be a nice
> addition to Python's pattern matching.
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/CLPYX3HUCH3J4LQEWSTBYBEXBSLJXHOO/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/N6XMXZ73P6GF24NHT4P345ZYDXPAYE4J/
Code of Conduct: http://python.org/psf/codeofconduct/