How to get the first N words from a string in Python

1 Answer

0 votes
s = "python c c++ java c#"

N = 3
lst = s.split()[:N]

first3 = ' '.join(lst)

print(first3)




'''
run:

python c c++

'''

 



answered Feb 8, 2022 by avibootz

Related questions

1 answer 186 views
1 answer 213 views
2 answers 285 views
2 answers 256 views
2 answers 260 views
1 answer 187 views
...