+ 1
I want to ask if there is a set of string is there like words=["Hi","Hello","Bye","See u"]and I want to print upto "Bye" then how can I do it using for loop
6 ответов
+ 3
for(int i=0;I<=words.length;i++){
if(words[i]=="Bye") {
break;
}}
+ 1
"I want to ask if there is a set of string"
A specific word or literal list of words? This is how you would ask if a specific value existed.
if "string" in words:
"I want to print upto "Bye""
for item in words:
if word[item] == "bye":
break
else:
print(item)
+ 1
I will tell u later because I want a time to write a code ok
0
at the risk of appearing naive, why not directly do it?
why do you want the for loop?
it would help to answer if we knew what other branches you need to tackle.
0
You don't need a for loop in order to do that:
// as list
print words[0:3]
output: ['Hi', 'Hello', 'Bye']
——————————————
// as plain
' '.join(words[0:3])
output: Hi Hello Bye
0
for e in words:
print(e)
if e=="bye":
break