Level 10 : What will be the output of the following code?


def alternating_signs(n):
    for i in range(n):
        yield (-1) ** i * i

gen = alternating_signs(5)
print(list(gen))

Author: SandhyaR | Tags: generator | 1736+ Python FAQs | Share
mapping-function | stack | factorial-function | counter-function | numeric | sys | application | slice | control-statement | heap-memory | object-attribute | multiple-inheritance | dictionary | integer | library | else-statement | global-variable | list-comprehension | debugging | error | list-comprehension | import-method | print | call | iterable | keyword | identifier | installation | exception-handling | lists | input-function | docstring | context-manager | attribute | constructor | input | bitwise-operator | decimal | expression | input-function | update | design-principle | python-repl | sum-function | generators-in-python | logical-operation | syntax-error | decorator | fabs-function | collections | filter | class-and-inheritance | max-min | mutable | indentation | polymorphism | generators | comparison | datetime | data-structures | memory-management | list-vs-tuple | data-type | comprehension | string-manipulation | complex-number | random | precedence | join | init | class-and-instance-variable | global | split | lambda-function | variable | class-and-object | operations | expand-tab | id-function | sum() | numpy | operator-or | immutability | assert | pickling-&-unpickling | copy | python_version | name-mangling | __future__ | parameter | tuple-unpacking | arithmetic-expression | raise | syntaxerror | staticmethod | yield | oop | postfix | operator | data-type | functional-programming | counter | __init_subclass__ | zip | dictionaries | matrix | binary-operation | access-modifier | destructor | swapping | assignment-operator | formal-and-actual-parameter | indexing | virtual-environment | sorting | conditional-statement | python-history | round-function | zip-function | odd-number | slicing | gil | def | while-else-loop | math-copysign | math | print-statement | tuple | choice | python | mathematical-function | function-argument | functions | enumerate() | python-module | boolean-and-non-boolean | min-function | list-operation | regular-expression | list-mutation | function | exception-handling | type-conversion | goto-function | global-keyword | while-and-for-loop | static-method | operator-and | overflow | version-check | matplotlib | asyncio-module | head-and-tail | touples | interpreter | string-formatting | map-function | mysql | string-concatenation | virtual-environment | string-formatting | bitwise-operator | file_handling | implementation | set | method | list-indexing | data-structure | default-mutable-argument | higher-order-function | control-flow | benefit | descriptors | random-function | syntax | file-handling | round | built-in | sorted | immutable-data-type | sys-module | return-statement | regex | list-method | methods | format | rollback | string-iteration | global-variable | complex | operand | identity-operator | nested-loop | collection | control-flow | range | error-handling | lambdas | loop-control | conversion | operator-overloading | software-design | comment | memory | with-statement | python-django | lambda | zfill-function | scientific-notation | encoding | statement | string-method | while-loop | inherit | precedence-and-associativity | loop | multithreading | match | function-and-scope | classes | mathematics | namespace | oops | __all__-attribute | min-max-function | module | basic | invalid-list | asyncio | typeerror | generator | for | binary | thread | deep-copy | class | list-join | recurssion | file-handling | matrix-list-comprehension | recursion | compute | arithmetic-operation | feature | string-method | namedtuple | dicts | data_structure | boolean | array | condition | type-conversion | escape-operator | version | inheritance | shallow-copy | pseudocode | frozenset | type_conversion | floating-point-precision | string-slicing | string-slicing | set-operation | logical-operator | identity-operator | objects | built-in-function | append | magic-method | threading | exponentiation | encapsulation | turtle | command-line-parsing | string | package-management | multiprocessing | int | iterator | datatype | file | logical-operator | center | pandas | list-slicing | async | exception | syntax-error | list | conditional-statement | operators | loops | bitwise | pep | filter-function | built-in-function | data-structure ...