About 266,000 results
Open links in new tab
  1. what is the difference between return and break in python?

    Mar 4, 2015 · break is used to end loops while return is used to end a function (and return a value). There is also continue as a means to proceed to next iteration without completing the current one. return can sometimes be used somewhat as a break when looping, an example would be a simple search function to search what in lst :

  2. Python: 'break' outside loop - Stack Overflow

    May 25, 2024 · a break in a loop, where this break is not under a condition. the code in your response is a case where break is not "directly" in the loop -- it is inside of a condition. somehow your last sentence was grammatically unclear to me :-) –

  3. python - How does break work in a for loop? - Stack Overflow

    I am new in Python and I got confused about the way that "break" works in a for loop. There is an example in Python documentation( break and continue Statements ) which calculates prime numbers in range (2, 10):

  4. How to break out of while loop in Python? - Stack Overflow

    Nov 11, 2024 · Don't use while True and break statements. It's bad programming. Imagine you come to debug someone else's code and you see a while True on line 1 and then have to trawl your way through another 200 lines of code with 15 break statements in it, having to read umpteen lines of code for each one to work out what actually causes it to get to the break.

  5. What does the percentage sign mean in Python [duplicate]

    Apr 25, 2017 · What does the percentage sign mean? It's an operator in Python that can mean several things depending on the context. A lot of what follows was already mentioned (or hinted at) in the other answers but I thought it could be helpful to provide a more extensive summary. % for Numbers: Modulo operation / Remainder / Rest. The percentage sign is an ...

  6. python - What does 'if not data: break' mean? - Stack Overflow

    Jul 27, 2013 · Except in our case, while block has a break in it. Should that break be hit, it will break out of the loop. Lets look at the while block: data = conn.recv(BUFFER_SIZE) if not data: break print "received data:", data conn.send(data) # echo This block is saying receive data on the connection conn reading at most BUFFER_SIZE bytes.

  7. python - What does "Break outside Loop" mean? - Stack Overflow

    Jul 9, 2017 · Beginner! I am trying to make a program that reads in X whole numbers and outputs (1) the sum of all positive numbers, (2) the sum of all negative numbers, and (3) the sum of all positive and nega...

  8. python - How can I break out of multiple loops? - Stack Overflow

    There is no way to do this from a language level. Some languages have a goto others have a break that takes an argument, python does not. The best options are: Set a flag which is checked by the outer loop, or set the outer loops condition. Put the loop in a function and use return to break out of all the loops at once. Reformulate your logic ...

  9. Python Break Inside Function - Stack Overflow

    Sep 20, 2016 · I am using Python 3.5, and I would like to use the break command inside a function, but I do not know how. I would like to use something like this: def stopIfZero(a): if int(a) == 0: b...

  10. What does the "yield" keyword do in Python? - Stack Overflow

    Oct 24, 2008 · And it works because Python does not care if the argument of a method is a list or not. Python expects iterables so it will work with strings, lists, tuples, and generators! This is called duck typing and is one of the reasons why Python is so cool. But this is …

Refresh