7 Risposte
+ 4
Like 1 hour to learn syntax is more than enough. But to learn when to use it, how to use it properly (python OOP is famously terrible) would be a much longer journey?
Why do u need OOP in python though?
+ 4
Romeo Beltran
Think of OOP as a grouping of variables and functions...
instead of separate unrelated variables and functions:
name = "Ben"
age = 10
def student_data(n, a):
print(n, 'is', a, 'years old')
student_data(name, age)
in OOP you group the data and the function into a single unit
class Student:
def __init__(self, n, a):
self.name = n
self.age = a
def student_data(self):
print(self.name, 'is', self.age, 'years old')
# then you use the class Student like this:
s1 = Student('Mickey', 17)
s1.student_data()
s2 = Student('Rick', 16)
s2.student_data()
+ 2
learning is different from being proficient. understanding the basics is easy, knowing when and how to use it properly takes a lot of time and practice.
Python OOP is a very simplified version. It's useful enough, though, for games, gui design, etc.
if you're trying to learn OOP with all the bells and whistles, learn Java.
+ 1
You can learn OOP syntax in only 30 minutes, but for training, you should write small projects and codes and 1 hour per day is enough.
+ 1
Whats the benefit of grouping them into a single unit? The syntax looks easier, and more readable in the first version.
Is there a reason to group them into a single unit, loke would it be faster in the long run or something?
+ 1
it's just a simple example, so the advantage is not apparent. it's even an over-complication, imo.
but OOP have the benefit of data encapsulation.
since the data is internal to the object, it's less prone to being accidentally altered by functions outside of the class itself.
it also makes it possible to pass the object as a single unit of data to other classes or functions. this can make our code more concise and simpler.
it also often makes it easier to reason about the code in general, since you have a higher level of abstraction to work with.
for more complex uses, you can add more methods that can manipulate the class data in various ways. just don't overdo it and turn the class into an incoherent mess.
I'm not a really big fan of OOP, since it can easily get overcomplicated. but if you keep it simple, it's a useful abstraction to consider. but for simple tasks, use imperative programming.
Also, most of Python's modules OOP, so it's useful to have a good working knowledge of it.
0
I cant even figure out what OOP in python is & i just read an entire article on it