Level 10 : what is the output for the below code?


funcs = []
for i in range(3):
    funcs.append(lambda: i)

print([f() for f in funcs])

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