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