Level 9 : What will the following code output?


class A:
    def __init__(self):
        self.data = "A"
    
    def display(self):
        print(self.data)

class B(A):
    def __init__(self):
        super().__init__()
        self.data = "B"

a = A()
b = B()
a.display()
b.display()

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