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