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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -