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