MasterHolbytla MasterHolbytla - 1 month ago 5
Python Question

Python detect character surrounded by spaces

Anyone know how I can find the character in the center that is surrounded by spaces?

1 + 1

I'd like to be able to separate the
in the middle to use in a if/else statement.

Sorry if I'm not too clear, I'm a Python beginner.


I think you are looking for something like the split() method which will split on white space by default.

Suppose we have a string s

s = "1 + 1"
chunks = s.split()
print(chunks[1]) # Will print '+'