A stupid class() question(s)

Hi all,

Q1:
Why doesn’t Python show the objective result instead of what I assumed was binary format? This raises more questions. -----

Q2:

What’s the deal with “… object at 0x7fdb4020fb10>”? Is it connected to the binary system? What questions would I need to ask to illuminate myself?

class tree:
    def __init__(self, roots, branches):
        self.roots = roots
        self.branches = branches

p = tree("this's is just an example", 4)
print(tree(3,4))
print(p)

Thanks… (a bit drunk…lol)

1: The __str__ method helps define a more human readable output. Or use dataclasses.dataclass to get something similar for free.

2: The hexadecimal number is (generally) the location in memory that the object is stored. Think of it as a way for the interpreter to find the object when it needs it.

What a fun way to sober up lol

1 Like

Would you write a sophisticated script in Python using class()?

Class() appears to me to be a function within a function (what’s not?). I haven’t discovered a conceptual advantage to using class() instead of dict(). I’ve only noticed that scrips using class() look neat…neat…

@Anno - Based on this and earlier posts, I think you are like a traveller visiting a strange country (Python Land) in a strange continent (Programming) trying to pick up the language by talking to random strangers on the street. My advise: At least consult a phrasebook from time to time :slight_smile:

It has entries for “class” “dict” and “function”.

2 Likes

If I wanted to have a method on a ‘thing’ its easier to have it on a class than a dict.

class Hello:
    def hi(self):
        print('hi')

Having a method to say ‘hi’ on a dict wouldn’t be as easy.

1 Like

Self appears to be an inverse function.
init seems needless to me… Isn’t format (self: A, B) simpler?

Perhaps the Python developer included the init() function because not doing so violates computer operational order…

Actually, he’s right…

My approach is like this:

Goal: Own Questions: Details (various resources)

To have a holistic picture of the structure of the Python language in mind, I need to first understand its structure by comparing my existing knowledge with that of Python.

sudo code:

Goal = Questions.self()