Level 5 : What is the output?


def squared_gen(limit):
    for i in range(limit):
        yield i ** 2

g = squared_gen(4)
print(sum(g))
print(sum(g))

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