search
[last updated: 2026-01-10]
Python home page
Python: Programming
-----
--------
# printing original string
print("The original string is : " + test_str)
# initializing N
N = 3
# Get Nth word in String
# using loop
count = 0
res = ""
for ele in test_str:
if ele == ' ':
count = count + 1
if count == N:
break
res = ""
else :
res = res + ele
# printing result
print("The Nth word in String : " + res)
Output :
The original string is : GFG is for Geeks
The Nth word in String : for
.
.
.
eof