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