-1

so I know how to check if a variable contains numbers. like :

variable.isdigit

but how to know if its not containing a number and it have letters or symbols or... in it.

Parsa Ad
  • 91
  • 6

2 Answers2

1

Please check the documentation, e.g. https://www.w3schools.com/python/python_ref_string.asp

  • the opposite of .isdigit(): not variable.isdigit()
amy989
  • 313
  • 1
  • 7
0

The easiest to find out about the type of the variable is to use type:

>>> x=1.23
>>> y=3
>>> z='blah'
>>> print(type(x), type(y), type(z))
<class 'float'> <class 'int'> <class 'str'>

If you need boolean tests, you have a bunch of other var.is* options:

x.isalnum()       x.isdecimal()     x.islower()       x.isspace()
x.isalpha()       x.isdigit()       x.isnumeric()     x.istitle()
x.isascii()       x.isidentifier()  x.isprintable()   x.isupper()
Andrej Prsa
  • 551
  • 3
  • 14
  • so .... which one of these "is" booleans are for letters or symbols? – Parsa Ad Mar 04 '22 at 15:13
  • isalpha() is for alphabet letters; alnum() is for alphanumerical, so it returns true for letters and numbers; isascii() is for all ascii symbols. You can use the `and` and `or` and `not` logic to get precisely what you need. – Andrej Prsa Mar 04 '22 at 15:20