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