Page 1 of 1

Python: Classes - # 3

Posted: Mon Oct 27, 2025 6:49 pm
by Jason

Code: Select all

class first_year_college_student():

	def __init__(self, age = 18, name):

	# The default is set to 18, unless specified in parameter.

	age = self.age

	name = self.name

	def print_age_and_name():

	print(f "The student's age is {self.age} and his or her name is {self.name}

first_year_college_student_1 = first_year_college_student()

first_year_college_student_1.print_age_and_name(Mary)

# Age is assumed to be 18.

first_year_college_student_2 = first_year_college_student()

first_year_college_student_2.print_age_and_name(25, Rob)

# Rob is different than many of these particular students being 25

Code: Select all

class name_of_college():

pass