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