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