+ 1
Hi! I need help with Python 3.
Hey, guys! I need your help writing the program. Can help compile a regular expression to see if the user input is an integer. (Examples: 4, -4, 243255)
6 ответов
+ 2
A digit can be referred to either with "\d" or "[0-9]". If you need to escape a character (for example, "-"), use a backslash, so "\-" in a regular expression will mean "-" (although with - it's just optional). Optional values have put a question mark afterwards (so "tables?" will accept table & tables); and to show that something should occur 1 or more times, put a + sign after it.
Five characters. I think you can conjure it yourself
+ 1
Cbr✔[ Most active ] Two of your three answers are wrong.
print("—".isalpha()) # False
print("42".isalpha()) # False
try:
int("42")
print("True")
except ValueError:
print("False")
# True
print(isinstance(type(set("42".split(" "))), int))
# False
0
Cbr✔[ Most active ] The fact that isalpha() returns False doesn't give us any information about it being a number.
print("—".isalpha())
# False, not an alpha
# Not a number either
Also, your new third method doesn't work for negative numbers.