Level 1 : What is the output of the following code?


from collections import defaultdict      
alphabet = defaultdict(int)      
alphabet['x'] = 1      
alphabet['y'] = 2      
print(alphabet['z'])

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