+ 1
What's object in oop?
23 ответов
+ 4
Technically, everything in Python is an object - it’s an object oriented programming language.
A plain old variable in Python is still an object (well a pointer, to the object which contains all the metadata and methods).
Creating your own class User is no different than using int…you are just using two different types of objects!
Both are classes, constructors are called etc. Sure it’s sensible and more convenient grouping data together, but I don’t see how that would help with running out of names - you still have to instantiate an object with a name.
Here’s something to try, in your Python terminal type ‘help(int)’.
I’ll copy a small section below, you will see its a class just like the user defined class.
Help on class int in module builtins:
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
…etc
So the answer to your question, what is an object in Python: everything.
+ 4
Hi Santiago Angel mancera apart from the many answers provided here. I found an extra good source to further your education. This site explains what OOP means, whats an object and how to create them. It provides many logical and easy to follow code examples. - Happy Coding!
https://realpython.com/python3-object-oriented-programming/
+ 2
python
Hope it's helpful to you
+ 2
No primitives in Python! Everything's an object.
Python is not Java.
Even a literal is an object, try:
print(type(“string”))
A string literal is a str object.
+ 2
…suggest you go an do a little research before telling me I don’t know what OOP is.
Millions of places online where you will find that you are clearly wrong. I’ve obviously rubbed you up the wrong way, but just like your “pass by pointer” you are wrong. Just accept it.
I’ve shown you through the builtins help but if your still not convinced then checkout intobject.c from the Python source code.
Even ask your Nvidia buddies, standards must be getting low around there…
+ 2
Ahahaha, right. Again you are making assumptions, I didn’t suggest you learn from bloggers - I suggested you learn from python source code.
I haven’t been trolling either - You insulted me first so deal with it!
That fact is you are incorrect, show me evidence otherwise and i will concede.
+ 2
Your going off again, I never stated Python was pure oop, where have I said pure?
I’m talking about the lack of primitives in python, that int is an object. That everything is an object in Python.
…you can keep your Kotlin example, this question is related to Python!
+ 2
Jay,
Thanks for your input, aside from the fact that magic methods shouldn't be invoked directly...
The error from your calling is wrong, try this which works fine:
print((5).__add__(3))
or
INTCON = 3
print(INTCON.__add__(4))
or for a boolean
print((True).__add__(False))
To expant on this, you could also add a space so that the 5 isn’t parsed as a float:
print(5 .__add__(3))
+ 1
Básicamente la OOP permite a los programadores escribir software, de forma que esté organizado en la misma manera que el problema que trata de modelizar.
+ 1
Everything is an object as stated above , i played around with python and they abstracted this by using metaclasses so it wont show
+ 1
He want to know what is oop as you said its a way to group releated things together, also distinguishing truth values on other ,
+ 1
Just think of object as obj of a class and when you declare a class, you have to create objects to access the data from that class.
Class A {
private:
Int age;
public:
void setAge(int Age){age=Age;}
Int getAge(){return age;}
};
Int main(){
A objA1; < creating an object
A objA2; < creating an object
objA1.setAge(22);
objA1.getAge();
objA2.setAge(32);
objA2.getAge();
objA3.setAge(54);
objA3.getAge();
As you can see you are creating different objects for that class.
}
0
Thanks Chris Coder