7. Private variables and name mangling

۰ نظر گزارش تخلف
Farnaz Baghban
Farnaz Baghban

#7 Python Programming Exercise

Construct a class Car with the following features:

create a class variable called color with value black

create 2 instance variables: brand and year

the instance variables are injected from outside - via a constructor

generate functions with which we can acquire the instance variables - these are called getters

Good luck!
======================================
#7 Python Programming Solution

class Car:

# class variable
color = 'black'

# constructor with instance variables
def __init__(self, brand, year):
self.brand = brand
self.year = year

# getter functions for the instance variables
def get_brand(self):
return self.brand

def get_year(self):
return self.year
=============================

نظرات

در حال حاضر امکان درج نظر برای این ویدیو غیرفعال است.

توضیحات

7. Private variables and name mangling

۰ لایک
۰ نظر

#7 Python Programming Exercise

Construct a class Car with the following features:

create a class variable called color with value black

create 2 instance variables: brand and year

the instance variables are injected from outside - via a constructor

generate functions with which we can acquire the instance variables - these are called getters

Good luck!
======================================
#7 Python Programming Solution

class Car:

# class variable
color = 'black'

# constructor with instance variables
def __init__(self, brand, year):
self.brand = brand
self.year = year

# getter functions for the instance variables
def get_brand(self):
return self.brand

def get_year(self):
return self.year
=============================