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