"End" inside a loop | Sololearn: Learn to code for FREE!


"End" inside a loop

When using an "end" inside a loop to end a program, it works properly for Code Coach challenges, but it displays an error message if I try to do the same on Jupyter Notebooks. Why? Is there a better option than using the "end" inside a loop to achieve the expected result? Here is an example: string = input() chars_set = set() for char in string: if char in chars_set: print('Deja Vu') end else: chars_set.add(char) print('Unique')

5/6/2020 11:32:19 AM

Isabela Poley

10 Answers

New Answer


If you want to end the whole program you can import sys. Then you can use sys.exit() at the desired location. The program will then end properly.


end is a keyword to the print function only not for python in general. print("Deja vu" , end="")


end is not a Python keyword. Do you mean 'break'?


As HonFu mentions end is not a valid Python keyword, I think you are confusing it with other syntax for other language. "break" is the Python substitute for end


"Break" would only end the loop, not the program.


It worked! Thank you, Crash!


Isabela Poley My pleasure!


Olá, Matheus Stefani. Esses dois cursos são visíveis apenas no aplicativo para smartphone. Não aparecem no site do SoloLearn.


Muito obrigado!! Isabela Poley


Hi Isabela, it does not belong to this topic but I saw you mentioned some courses here, but I cannot find it. Please, where I can find it? "The new SoloLearn courses on "Data Science with Python" and "Machine Learning" are a great way to start!" Thanks