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