Last modified: April 05, 2020

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


2. example

string = "python is a great language"

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




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.