Level 1 : What will be the output of the following Python program?


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

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