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