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