Logic Building
# Take string input
s = input("Enter a string: ")
# Get first word
words = s.split()
if len(words) > 0:
print(f"First word: {words[0]}")
else:
print("No words found")Output
Enter a string: Hello World Programming First word: Hello
Split string and get first element.
Key Concepts:
- split() splits into words
- words[0] is first word
- Check if words exist