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