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