Level 9 : What will this print?


def numbers():
    yield 1
    raise Exception("Error!")

g = numbers()
print(next(g))
print(next(g))

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