Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python classes
#1
Dear python users,

As a python newbie I started two months ago learning a bit of coding. By learning some topics of Python some questions came to my mind and I would like to ask here I someone could help me with this case(s). Now I am kind of assuming what the solution would be but I prefer doing it in the correct way avoiding frustrations in the future Big Grin .

The query:
Inside class objects, should I use the SELF argument only in the __init__ def?

For example:
class CountFromBy:
    
    def __init__(self, v: int=0, i: int=1):
        self.val = v
        self.incr = i

    def increase(self):
        self.val += self.incr

    def __repr__(self) -> str:
        return str(self.val)
And what is the function of "v" and "i" in the __init__ object? Should it be better to used the same initials as "val" behind the self argument?

Hopefully the query description is understandable, please let me know if additional information is needed.

Like to hear!
Reply


Messages In This Thread
Python classes - by Python_User - Aug-01-2020, 08:13 AM
RE: Python classes - by Gribouillis - Aug-01-2020, 08:50 AM
RE: Python classes - by Python_User - Aug-01-2020, 09:46 AM
RE: Python classes - by snippsat - Aug-01-2020, 10:27 AM
RE: Python classes - by Python_User - Aug-02-2020, 08:04 AM
RE: Python classes - by Gribouillis - Aug-02-2020, 09:32 AM
RE: Python classes - by Python_User - Aug-02-2020, 09:41 AM
RE: Python classes - by snippsat - Aug-02-2020, 10:08 AM
RE: Python classes - by deanhystad - Aug-02-2020, 10:50 AM
RE: Python classes - by Python_User - Aug-02-2020, 03:02 PM
RE: Python classes - by deanhystad - Aug-02-2020, 03:49 PM
RE: Python classes - by Python_User - Aug-02-2020, 05:53 PM
RE: Python classes - by deanhystad - Aug-02-2020, 08:18 PM
RE: Python classes - by Python_User - Aug-03-2020, 06:38 PM
RE: Python classes - by bowlofred - Aug-03-2020, 08:13 PM
RE: Python classes - by Python_User - Aug-04-2020, 06:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Classes rob101 4 593 Feb-05-2024, 06:51 PM
Last Post: rob101
  Understanding Python classes PythonNewbee 3 1,248 Nov-10-2022, 11:07 PM
Last Post: deanhystad
Sad Python classes PythonNewbee 4 1,107 Nov-09-2022, 01:19 PM
Last Post: deanhystad
  Inheritance vs Instantiation for Python classes mr_byte31 7 3,016 Oct-14-2021, 12:58 PM
Last Post: mr_byte31
  Understanding Python super() for classes OmegaRed94 1 1,881 Jun-09-2021, 09:02 AM
Last Post: buran
  Python Classes leodavinci1990 1 2,123 Nov-27-2019, 07:25 AM
Last Post: buran
  Using classes? Can I just use classes to structure code? muteboy 5 5,153 Nov-01-2017, 04:20 PM
Last Post: metulburr
  use of classes in python Lux 2 3,572 Aug-19-2017, 12:29 PM
Last Post: hbknjr
  python classes prsdll6 14 7,545 Aug-17-2017, 07:26 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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