Last modified: Jan 10, 2023 By Alexander Williams
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.
#string string = "python is a great language" #convert string to list and get the first item first_world = string.split() #print print(first_world)
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.