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