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