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