A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Python | Demonstrate an Example of break statement
Q:

Python | Demonstrate an Example of break statement

0

break is a keyword in python just like another programming language and it is used to break the execution of loop statement.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Example 1:

for i in range(1,11):
    if(i==6):
        break
    print(i)

Output

1
2
3
4
5

Example 2: In this example, we are printing character by character of the value/string “Hello world” and terminating (using break), if the character is space.

for ch in "Hello world":
    if ch == " ":
        break
    print(ch)

Output

H
e
l
l
o

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now