Level 5 : What will this code output?


def word_length(words):
    for word in words:
        yield len(word)

g = word_length(["hello", "python", "iterator"])
print(sum(g))
print(sum(g))

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