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