Level 9 : What will be the output of the following Python program?


i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)

Author: Devakanth | Tags: while-loop | 1859+ Python FAQs | Share
string-method | list-indexing | condition | conversion | conditional-statement | __all__-attribute | math | data-type | postfix | print-statement | control-flow | __future__ | reading-and-writing-files | operations | raise | pep | precedence | binary | dictionary-methods | difference-between-threads-and-processes | benefit | python-repl | numeric | context-manager | array | application | type_conversion | python-django | defining-functions | data-type | using-the-threading-module | aggregating-data-with-functools.reduce() | thread-synchronization | center | raise-statement | compute | comment | zip | class-and-inheritance | nested-loop | writing:-write(),-writelines() | zfill-function | thread-safe-data-structures-(queue.queue) | precedence-and-associativity | descriptors | objects | using-lists-as-stacks | zip-function | debugging | built-in-modules | range | counter | choice | advanced-file-operations | polymorphism | datetime | syntax | decorator | error | destructor | parameter | recursion | list-slicing | identifier | syntaxerror | assert | bitwise-operator | collections | exponentiation | access-modifier | booleans | list-comprehension | operators | asyncio-module | staticmethod | operator-and | encoding | working-with-temporary-files-using-tempfile | error-handling | literal-characters-and-special-characters | dictionary | data-structures-in-python | thread | random-function | working-with-file-paths | type-conversion | factorial-function | for | random | list-operation | asyncio | data-type-conversions | default-mutable-argument | control-statement | string-method | lambdas | loop | regular-expressions | list-vs-tuple | directory-operations | sorted | list-methods-and-slicing | object-attribute | fabs-function | __init_subclass__ | tuple-unpacking | floating-point-precision | overriding-methods | lists | boolean-and-non-boolean | immutable-data-type | string-slicing | parsing-with-strptime | generators-in-python | dataframe-and-series-objects | single-inheritance | swapping | init | multiprocessing | round | why-use-multiprocessing-over-threading?-(gil) | loop-control | datetime.date,-datetime.time,-datetime.datetime | introduction-to-threads | boolean-masking | regex | global-variable | indexing:-loc-vs-iloc | python | string-concatenation | multiple-inheritance | regular-expression | logical-operator | int | inheritance | return-statement | matplotlib | lambda-function | formal-and-actual-parameter | format | method | shallow-copy | exception | logical-operator | data-types | list,-set,-and-dictionary-comprehensions | error-handling | docstring | introduction-to-python | namedtuple | global-keyword | using-join()-and-is_alive()-methods | tuple | update | enumerate() | comprehension | arithmetic-operation | assignment-operator | using-else-and-finally | data-structure | list-method | key-value-pairs | variable | identity-operator | id-function | identity-operators-(is,-is-not) | input | comparison | mysql | version-check | multiple-inheritance | conditional-statement | using-yield-in-functions | file_handling | class-and-instance-variable | deep-copy | multiple-except-blocks | sys-module | exception-handling | odd-number | test-discovery | counter-function | numpy | inherit | stack | using-os-and-pathlib-modules | decimal | working-with-binary-files-(rb,-wb) | pandas | async | max-min | multithreading | arithmetic-expression | opening-files-(open()) | string-formatting | binary-operation | copy | pass | matrix | oops | creating-custom-modules | syntax-error | filter | pickling--unpickling | memory | expand-tab | attribute | keyword | function-and-scope | virtual-environment | mathematical-function | recurssion | global-variable | higher-order-function | operator-overloading | dictionaries | data_structure | heap-memory | conditional-statements | feature | function-argument | indentation | iterable | functional-programming | set | sum() | python-module | else-statement | matrix-list-comprehension | with-statement | sum-function | head-and-tail | using-map()-for-transformations | type-conversion | time-series-with-pandas | creating-and-starting-threads | python-operators | loop-control-statements | namespace | bitwise-operator | yield | tuple-methods | implementation | syntax-error | while-loops | filter-function | datatype | def | call | while-else-loop | introduction-to-multiprocessing | design-principle | anchors-(^,-$) | using-assertions-(assertequal,-assertraises) | type-conversion-and-casting | static-method | map-function | constructor | arbitrary-arguments-(*args,-**kwargs) | managing-directories-with-os-and-shutil | frozenset | immutability | indexing | identity-operator | built-in | built-in-function | basic | invalid-list | slice | operator-or | iterators | oop | built-in-function | else | class-and-object | generator | pseudocode | package-management | command-line-parsing | rollback | name-mangling | control-flow | threading | handling-missing-values-(fillna,-dropna) | math-copysign | logical-operators | mapping-function | collection | lambda-functions | functional-programming | complex-number | typeerror | slicing | data-structures | turtle | integers | class-decorators | methods | sorting | functions | integer | interpreter | min-function | class | virtual-environment | touples | input-function | membership-operators-(in,-not-in) | strings | round-function | mutable | scientific-notation | iterator | lambda | filtering-and-indexing | list-comprehension | set-operation | module | magic-method | bitwise | assignment-operators | dicts | string-manipulation | string | data-structure | logical-operation | reading:-read(),-readline(),-readlines() | method-overloading | file-handling | floats | python-syntax-and-structure | joining-and-merging-dataframes | software-design | global | mathematics | operand | match | python-history | default-arguments | file-handling | quantifiers-(*,-+,-?,-{}) | formatting-with-strftime | dictionary-comprehensions | complex | gil | loops | sets | print | classes | version | split | string-methods | exception-handling | python_version | string-formatting | function | append | sorting-and-ranking | memory-management | boolean | library | list | sys | file | list-join | installation | goto-function | working-with-dates-and-times | encapsulation | while-loop | escape-operator | tuples | intering | generators | operator | list-mutation | min-max-function | while-and-for-loop | walking-through-directories-using-os.walk() | overflow | unit-testing | statement | list-comprehensions | join | import-method | string-iteration | string-slicing | input-function | expression | reading-and-writing-large-files-efficiently ...