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