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