-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?

  • 1
    Does this answer your question? [How do I check if a given Python string is a substring of another one?](https://stackoverflow.com/questions/5143769/how-do-i-check-if-a-given-python-string-is-a-substring-of-another-one) – Pranav Hosangadi Apr 09 '21 at 19:32
  • Please take the [tour], read [what's on-topic here](/help/on-topic), [ask], and the [question checklist](//meta.stackoverflow.com/q/260648/843953). Please note that [asking on Stack Overflow is not a substitute for doing your own research.](//meta.stackoverflow.com/a/261593/843953) – Pranav Hosangadi Apr 09 '21 at 19:33

2 Answers2

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")

lightstack
  • 321
  • 2
  • 8
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")
Kristie
  • 92
  • 8