Page 1 of 1

Python: Classes

Posted: Mon Jul 28, 2025 10:47 pm
by Jason

Code: Select all

class Truck:

	machine_type = "automobile"
	
		def _init_(self, brand, model):
	
		self.brand = brand
	
		self.model = model
	
theTruckOfKenny = Truck(Ford, Ranger)

print(theTruckOfKenny.brand)

print(theTruckOfKenny.model)

print(theTruckOfKenny.machine_type)

# The last printed word would refer to automobile for Kenny's truck or for any other truck object made.
	

Code: Select all

theTruckOfDave = Truck(Chevy, S10)

print(theTruckOfDave.brand)

print(theTruckOfDave.model)

print(theTruckOfDave.machine_type)