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