Level 1 : what is the output of the following code?


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

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