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