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