Very basic question. We have the code:
a = input("how old are you")
if a == string:
do this
if a == integer (a != string):
do that
Obviously it doesn't work that way. But what is the easiest way to do this. Thanks for any answers in advance.
We could also say:
if string in a:
do this
You can use
str.isdigit
andstr.isalpha
:help on
str.isdigit
:help on
str.isalpha
:Seen that you use input() in tour example you should know that input always give you a string. And you need to cast it to the correct type, EG: Int, or Float.
You can use a.isalpha(), a.isdigit(), a.isalnum() to check if a is composed of letters, numbers, or a combination of numbers and letters, respectively.
The Python docs will tell you in more detail the methods you can call on strings.