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