0

words = ["hello", "world", "spam", "egg"]

How to print first 3 words

3rd Nov 2020, 1:37 AM
Sushil Mundhra
6 Réponses
+ 7
And if you just want the words, print(*words[:3])
3rd Nov 2020, 5:40 AM
David Ashton
David Ashton - avatar
+ 5
Er, Serval Toukap Nono, did you notice Shadoff posted the same answer an hour previously? 😄
3rd Nov 2020, 8:30 AM
David Ashton
David Ashton - avatar
+ 2
print(words[:3])
3rd Nov 2020, 4:56 AM
Shadoff
Shadoff - avatar
+ 1
Hello, You can use while loop and len function to print element for array x=0 while(x<=(len(words)-2)): print(words[x]) x +=1 Refer following code: https://code.sololearn.com/cZ7Uyy16rRkY/#py
3rd Nov 2020, 2:05 AM
AjayGohil
+ 1
David Ashton oups Sorry 😅
3rd Nov 2020, 10:13 AM
Serval Toukap Nono
Serval Toukap Nono - avatar
0
a = [1,2,3,4] [print(i) for i in a[:3]] out: 1 2 3
3rd Nov 2020, 1:50 AM
Flash