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


class A:
    def __init__(self):
        self.x = 1

class B(A):
    def __init__(self):
        super().__init__()
        self.y = 2

obj = B()
print(hasattr(obj, 'x'), hasattr(obj, 'y'))

Author: VenuEmmela | Tags: inherit | 1736+ Python FAQs | Share
min-function | python-repl | feature | math-copysign | destructor | bitwise-operator | sorted | __all__-attribute | decorator | while-else-loop | syntaxerror | max-min | list-join | data-type | postfix | staticmethod | mutable | enumerate() | list-indexing | multithreading | for | virtual-environment | yield | random | list-comprehension | update | string-iteration | error | matrix | typeerror | parameter | control-flow | gil | choice | while-loop | round-function | pickling-&-unpickling | matrix-list-comprehension | oop | context-manager | version | identity-operator | access-modifier | interpreter | keyword | integer | generators-in-python | goto-function | list | python-django | global-variable | decimal | complex | collection | id-function | precedence-and-associativity | type_conversion | method | lists | default-mutable-argument | error-handling | heap-memory | type-conversion | command-line-parsing | call | deep-copy | global | dictionary | complex-number | min-max-function | control-flow | file_handling | counter | recurssion | constructor | docstring | methods | file-handling | assignment-operator | asyncio-module | version-check | lambda | sys-module | input-function | init | datatype | string-manipulation | random-function | arithmetic-operation | threading | operator-and | tuple-unpacking | comprehension | pep | conditional-statement | list-slicing | precedence | __init_subclass__ | print-statement | multiprocessing | boolean-and-non-boolean | swapping | string-slicing | numeric | string-slicing | file | turtle | built-in-function | datetime | else-statement | memory-management | boolean | variable | loop-control | debugging | filter | iterator | scientific-notation | fabs-function | objects | __future__ | mapping-function | operator | sorting | indexing | encoding | basic | indentation | loop | dicts | logical-operation | round | lambda-function | generator | built-in-function | immutability | filter-function | expand-tab | file-handling | zip | sys | polymorphism | counter-function | immutable-data-type | global-keyword | string-method | range | statement | classes | exponentiation | comment | input-function | mathematics | function-and-scope | assert | touples | syntax-error | regex | package-management | matplotlib | raise | pseudocode | odd-number | functional-programming | iterable | regular-expression | list-vs-tuple | sum() | slicing | data_structure | installation | frozenset | bitwise-operator | operator-overloading | attribute | logical-operator | module | encapsulation | with-statement | identity-operator | built-in | print | virtual-environment | multiple-inheritance | library | escape-operator | namedtuple | match | factorial-function | loops | global-variable | string-formatting | operator-or | application | class | condition | class-and-object | operators | slice | object-attribute | oops | control-statement | python | thread | higher-order-function | zfill-function | dictionaries | join | tuple | python-module | operations | input | mysql | operand | recursion | binary-operation | collections | set-operation | comparison | function-argument | python_version | inheritance | stack | list-comprehension | class-and-instance-variable | string | invalid-list | exception | pandas | exception-handling | head-and-tail | type-conversion | logical-operator | def | functions | compute | copy | center | asyncio | string-concatenation | binary | formal-and-actual-parameter | implementation | magic-method | math | data-structure | benefit | name-mangling | expression | inherit | syntax-error | set | memory | python-history | split | design-principle | descriptors | array | rollback | namespace | data-type | numpy | string-method | mathematical-function | bitwise | list-mutation | data-structure | zip-function | while-and-for-loop | format | exception-handling | string-formatting | sum-function | lambdas | list-operation | floating-point-precision | identifier | static-method | generators | list-method | syntax | nested-loop | shallow-copy | function | arithmetic-expression | import-method | software-design | async | append | conversion | data-structures | int | overflow | return-statement | map-function | class-and-inheritance | conditional-statement ...