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