Python Forum
[split] Python Class Problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Python Class Problem
#1
if classes are objects - why are they called classes ?

also, objects have attributes (size, shape, color) and functions (hammer is for nails, a car for transportation, a tree produces fruits...)

you can use objects in order to do something...products are designed for a certain operation, the fact they are designed means they a designation...

where is the correlation to classes ?
Reply
#2
class Hammer:
    self.size = "small"
    self.shape = "hammer shape"
    self.color = (50, 50, 50)

    def drive_nail(self):
        if nail.driven = False:
            self.rect.y -= 20
Reply
#3
okay i see,
so a class is really a description of an object, true ?

and still i haven't understood why is it called a class...
Reply
#4
(Apr-29-2020, 06:09 AM)astral_travel Wrote: so a class is really a description of an object, true ?

yes - in general sense it's a "blueprint" of a thing. You can read more
https://en.wikipedia.org/wiki/Class_(com...ogramming)

so, for example, in this case it would make more sense if the class is named FileLoader (i.e. thing), than file_load (i.e. action)


(Apr-29-2020, 06:09 AM)astral_travel Wrote: and still i haven't understood why is it called a class...

what exactly worries you in class? Even outside of programming one of meanings of class is set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality.
https://www.merriam-webster.com/dictionary/class (see 3)
https://www.oxfordlearnersdictionaries.c...sh/class_1 (see 8)
https://www.lexico.com/definition/class (see 1)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
okay, now i got the meaning of class,

what i meant to say though, is that - usually when you define things (class or methods/functions) - the definition and functionality of things - is much more abstract... so how do you relate to abstract things ?
Reply
#6
you really need to read on object oriented programming basics:
class basics
class - intermediate - inheritance
class - intermediate - operator overloading

brief example:
class Car:
    def __init__(self, name, fuel, color):
        self.name = name
        self.fuel = fuel
        self.color = color

    def __str__(self):
        return (f'{self.name} is {self.color} {self.fuel} car')


car1 = Car("John's_SUV", 'diesel', 'red')
car2 = Car("Jane's car", 'petrol', 'blue')

print(car1)
print(car2)
Output:
John's_SUV is red diesel car Jane's car is blue petrol car
class Car is a blueprint of an object. As the name suggest it's a car and it has name, fuel and color attributes/properties
The class Car is abstract definition of some thing/object. We can instanciate as many cars as we want, e.g.
car1 is red, diesel and has "name" - John's car
car2 is blue, petrol and has "name" - Jane's car
I've split thread, so that we don't hi-jack the other thread
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
okay, i will read it...

i'll try to explain better what i mean by abstract... :

when you have a car and its attributes - it is a physical object...you can think/imagine its attributes and functions...it's something you can touch...

but when, say, you have an iterator - how do you relate to an iterator ? how do you make the abstract - physical ?

when i relate to physical things - everything is understood, it's no problem...
when you make something abstract physical - you basically turn it into a machine, a machine you can relate to...with your senses...

i guess what i'm trying to say is - how do you bridge the gap between the abstract and the physical..

i hope you get what i'm trying to convey...
-----------------------------------

about the split, no sweat...
Reply
#8
Some things in software don't have physical counterparts. They are abstractions that provide you an interface to do something useful in a program - like being able to iterate over some sequence in an efficient way, or performing operations against a database, for example. Abstractions are more about the what you can do, than the how. That even goes for abstractions we write ourselves - of course to implement them, we care about the how, but when we read code that uses them, we care more about the what.
Reply
#9
But why do you think in terms of physical/tangible (i.e. something you can touch)? It's not different with the abstract concepts. I understand that initially it may be somewhat difficult, but it's no different than understanding the abstract concept itself. Actually understanding the concepts itself is the first step in order to model it, to describe it as a class. It's no different than understanding abstract concepts e.g. in school. Think of it as "thing" or "object" if you like (by the way in python3 all classes inherit from object - the base class for all classes). Think what attributes it has and are of interest of you. If it helps you may try to distinguish properties (i.e. the characteristics) and methods (what it can "do", actions).


I really don't know how to better explain it.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
but programs are mechanical aren't they ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Class test : good way to split methods into several files paul18fr 4 401 Jan-30-2024, 11:46 AM
Last Post: Pedroski55
  [split] Class takes no arguments bily071 2 597 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  Practice problem using lambda inside the class jagasrik 3 2,106 Sep-12-2020, 03:18 PM
Last Post: deanhystad
  Python Class Problem JPCrosby 2 2,230 Apr-28-2020, 06:18 PM
Last Post: buran
  Class problem duckduck23 2 1,973 Feb-10-2020, 08:52 PM
Last Post: jefsummers
  Class code problem from CS Dojo YouTube Dixon 3 2,215 Feb-04-2020, 10:23 PM
Last Post: snippsat
  Class Problem scratchmyhead 3 2,258 Nov-19-2019, 08:28 AM
Last Post: Larz60+
  split by character class Skaperen 3 2,290 Jul-15-2019, 02:29 AM
Last Post: Skaperen
  re.split multiple delimiters problem gw1500se 2 3,562 Jun-24-2019, 02:43 PM
Last Post: gw1500se
  problem with class method AmirAB 3 3,327 Feb-13-2019, 01:51 AM
Last Post: AmirAB

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020