Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python class noob
#1
Hi I need help I want my code to make it so it does print the message but it dosent seem to work.

class Bil:
    __modelYear = ()  # private
    Status = ()

    def set_modelYear(self, Year):
        self.__modelYear = Year

    def get_modelYear(self):
        return self.__modelYear


def main():
    fiat = Bil()
    fiat.set_modelYear(2017)
    print('Har nu skaffat mig en bil av ', fiat.get_modelYear(), 'års modell')
Reply
#2
you didn't call main
main()
Reply
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python WebsocketServer ? its probably simple but im a noob. qbot333 1 1,981 Jun-03-2020, 06:30 PM
Last Post: ingnelson
  Python on Linux, Total Noob to Both halcyon 4 3,071 May-27-2019, 10:40 AM
Last Post: heiner55
  Maya Python Noob Question Iurii_Ledin 2 3,294 Jun-08-2018, 09:09 PM
Last Post: Iurii_Ledin
  Converting c++ class to python class panoss 12 11,866 Jul-23-2017, 01:16 PM
Last Post: Larz60+
  Noob question about python and Maxplus Strator 0 2,641 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