Level 5 : What will be the output of the following Python code ?


x = 2
for i in range(x):
    x -= 2
    print (x)

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