Karen
0
Q:

python print a specific word of a string

# initializing string   
test_string = "This is a string containing any text you want."

# using split() to extract words from string 
test_string_split = test_string.split() 

# printing result 
print(str(test_string_split)) 

# since the result is an array, you can print a specific part of the array just like you normally can with one
print(test_string_split[0])

# You also do it all in one line: (prints the first word of 'test_string')
print(test_string.split()[0])
0

New to Communities?

Join the community