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