简体   繁体   中英

Python logical NOT operator for regular expressions

I tried searching for this answer online but I haven't found any luck. I am wondering if python supports a logical not operator (usually ',') in other languages for an if statement. or any control statement really, For example. I am looking to achieve this functionality.

if !(re.search('[0-9]', userInputVariable):
    fix error and report to user

...Proceed with rest of code...

Where basically if the user does not input a number I correct it to a default value and proceed with script

Thanks!

You're looking for the not operator.

But that's not how you check for a number.

try:
  int(userInputVariable)
except ValueError:
  print "Not a number"

...

if not userInputVariable.isdigit():

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM