-1
x = input("enter input: ")

if x == "hello":
    print ("it does")

How would I detect if x has hello stored even if it has other charaters/strings?

2

2 Answers 2

0

This is as simple as using the in keyword.

x = "123hellomore"
if "hello" in x:
    print("Hi there")

This only detects hello, if it is unobstructed so still in one word (not like "**hel*lo")

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you lighstack I appreciate it.
I'd be happy about an upvote if I helped you :)
0

If entered input is single string then x below will be array of one element, if entered input is space separated strings (string of strings) then x will be array of multiple strings, below code handles both options

x = input("Enter input: ").split()
for y in x:
   if y=="hello"
      print("it does")

1 Comment

I know this works but would you mind explaining how it works?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.