Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python class noob
#3
Private Hand not in Python,and use of getters/setters not at all for simple attribute access.
Then it can look this.
class Bil:
    def __init__(self, model, year):
        self.model = model
        self.year = year

car = Bil('Fiat', 2017)
print(f'Har nu skaffat mig en {car.model} av {car.year} års modell')
# Setter(The Python way)
car.year = 2020
print(f'Har nu skaffat mig en {car.model} av {car.year} års modell')
Output:
Har nu skaffat mig en Fiat av 2017 års modell Har nu skaffat mig en Fiat av 2020 års modell
Reply


Messages In This Thread
Python class noob - by nallster7 - Sep-17-2020, 10:21 PM
RE: Python class noob - by Yoriz - Sep-17-2020, 10:36 PM
RE: Python class noob - by snippsat - Sep-17-2020, 10:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python WebsocketServer ? its probably simple but im a noob. qbot333 1 2,041 Jun-03-2020, 06:30 PM
Last Post: ingnelson
  Python on Linux, Total Noob to Both halcyon 4 3,212 May-27-2019, 10:40 AM
Last Post: heiner55
  Maya Python Noob Question Iurii_Ledin 2 3,373 Jun-08-2018, 09:09 PM
Last Post: Iurii_Ledin
  Converting c++ class to python class panoss 12 12,109 Jul-23-2017, 01:16 PM
Last Post: Larz60+
  Noob question about python and Maxplus Strator 0 2,706 May-16-2017, 05:07 PM
Last Post: Strator

Forum Jump:

User Panel Messages

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