1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] What are magic methods tied to type str? [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 30, 2024 às 22:32.

  1. Stack

    Stack Membro Participativo

    Ok so I am trying to learn Python. I notice that -

    string = 100
    type(string)
    <class 'int'>
    dir(string)
    ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__
    │divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '_
    │_getattribute__', '__getnewargs__', '__getstate__', '__gt__', '__hash__', '__index__', '__init__', '
    │__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__',
    │ '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod_
    │_', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__
    │', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__r
    │xor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__tru
    │nc__', '__xor__', 'as_integer_ratio', 'bit_count', 'bit_length', 'conjugate', 'denominator', 'from_b
    │ytes', 'imag', 'is_integer', 'numerator', 'real', 'to_bytes']


    That what I'm trying to understand is what are all those magic methods? I think I halfway understand that an integer attribute is subject to object oriented programming, but is there anything else?

    Continue reading...

Compartilhe esta Página