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