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