Check if a character is inside a string via a variable in Python? -


this question has answer here:

i newbie in python. making program take input user , check if number inside in string. checking taking in variable. not correct check via variable?

user_string=input("enter word:") print (user_string) index in (0,9):     number=str(index)           #typecasting int string      if number in user_string:   #check if number exist in string     print ("yes") 

output:

enter word:helo2 helo2 

you can use string method isdigit() on each character in generator expression within any. short-circuit upon finding first numeric character (if 1 present)

>>> user_string = 'helo2' >>> any(i.isdigit() in user_string) true  >>> user_string = 'hello' >>> any(i.isdigit() in user_string) false 

Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -