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