+ 1
What's object in oop?
23 Answers
+ 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