ItSolutionStuff.com

How to Get First Word from String in Python?

By Hardik Savani • October 30, 2023
Python

Hello Friends,

This tutorial shows you python get first word from string. This post will give you a simple example of python get first word in string. It's a simple example of how to get first word in string python. We will use how to get first word from string in python.

In this example, i will add myString variable with hello string. Then we will use split() function to getting first word from string in python. So, without further ado, let's see simple examples: You can use these examples with python3 (Python 3) version.

Example:

main.py

# Declare String Variable
myString = "Hello This is ItSolutionStuff.com"
  
# Getting First Word from String
firstWord = myString.split()[0]
  
print(firstWord)

Output:

Hello

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Python Convert base64 String to JPEG Image Example

Read Now →

Python Convert base64 String to PNG Image Example

Read Now →

How to Capitalize String in Python?

Read Now →

Python Create an Empty Text File Example

Read Now →

Python String Convert to Lowercase Example

Read Now →

Python String Convert to Uppercase Example

Read Now →

How to Find Sum of All Elements in List in Python?

Read Now →

Python Convert List into String with Commas Example

Read Now →

How to Convert List into String in Python?

Read Now →

Python Split String into List of Characters Example

Read Now →

How to Convert String into List in Python?

Read Now →

Python Remove Empty String from List Example

Read Now →

Python Get First Date of Last Month Example

Read Now →