Skip to content
Advertisement

Tag: python-3.10

New union shorthand giving “unsupported operand type(s) for |: ‘str’ and ‘type'”

Before 3.10, I was using Union to create union parameter annotations: Now, when I use the new union shorthand syntax: I get the error: TypeError: unsupported operand type(s) for |: ‘str’ and ‘type’ Is this not supported? Answer The fact that it’s being used as a type hint doesn’t really matter; fundamentally the expression “Vector” | float is a type

Using the “in” operator in Python 3.10 Match Case

Is there a “in” operator in python 3.10 Match Case like with if else statements if “n” in message: the in operator doesn’t work in match case This doesn’t work. How to have something like the “in” operator in Match-Case. Answer In match-case we can use the split() method on the message string. Example: Here, the string can be split

I want to distinguish between true digit and a string digit

I want to check a ‘x’ string whether it is a digit or not in advance. ‘1’ is naturally a digit. But and I will use ① what is calld a string number very much. I don’t know the range of string numbers IDE judges as a digit. ‘①’.isdigit() returns True. ‘⑴’.isdigit() returns True. ‘ⅰ’ or ‘Ⅰ’ returns False. ‘㈠’

Advertisement