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