get the first word of string in python (simple way)

in this tutorial, we'll learn how to get the first word of a string using a simple way.

1. syntax

string.split()[0]

2. example


#string
string = "python is a great language"

#convert string to list and get the first item
first_world = string.split()[0]

#print
print(first_world)

output

python

as you can see, "python" is the first item of our string.


now, let's see how we did that

first we've converted string to a list by using split() built-function, then got the first item in the list by using list index.

English today is not an art to be mastered it's just a tool to use to get a result