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


def f():
    global a
    print(a)
    a = "hello"
    print(a) 
a = "world" 
f()
print(a)

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