Level 9 : What will this code output?


import threading
x = 0

def inc():
    global x
    for _ in range(1000):
        x += 1

t1 = threading.Thread(target=inc)
t2 = threading.Thread(target=inc)
t1.start(); t2.start()
t1.join(); t2.join()

print(x)

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