Lets say i have myVariable = ‘Hello world’
How can I get just “World”? Ive tried a bunch of ways.
I am trying to make a chat bot at the moment, and I am making a settings command where you type :BotSettings
in a input.
Asked
Active
Viewed 35 times
-2

TheWall
- 11
- 5
-
https://docs.python.org/3/tutorial/introduction.html#strings – chepner Jan 12 '22 at 20:57
-
Does this answer your question? [How do I get a substring of a string in Python?](https://stackoverflow.com/questions/663171/how-do-i-get-a-substring-of-a-string-in-python) – Junior Jan 15 '22 at 06:38
2 Answers
0
If I have
myVariable = "Hello World"
, how do I make it "World"?
myVariable = "World"
If I have
myVariable = "Hello World"
, how do I find the second word?
myVariable = myVariable.split()[1] # "World"
If I have
myVariable = "apple Hello World banana"
, how do I find everything written after "Hello"?
_, _, myVariable = myVariable.partition("Hello ")

Jack Deeth
- 3,062
- 3
- 24
- 39