Python: Classes - # 3

Post Reply
User avatar
Jason
Site Admin
Posts: 809
Joined: Tue Jul 01, 2025 10:13 am

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



 

POSTREACT(ions) SUMMARY

Post Reply