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