Do if by denying a boolean in Python

Asked

Viewed 1,109 times

7

How do I make for the if check a boolean negation, as below:

self.senha = Gugu_0099

    for i in self.senha:
         if i.isdigit() and i.isalpha():
               total_simbolos += 1

I want you to get into this if if the character is neither number nor alphabet.
When studying PHP it was possible to use exclamation to show negation, for example:
!i.isdigital()

2 answers

9


Just use the not.

condition = False

if not condition:
  print('Entrou no if')
  • I was having a similar problem,!

3

You can do it like this:

if not (u0 <= u <= u0+step):
    u0 = u0+ step # change the condition until it is satisfied
else:
    do sth. # condition is satisfied

is just an example of if, is just you adjust the conditions of if.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.