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