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