Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 6

No change in size, 13:52, 27 November 2017
PART 1 - Creating a Class
== PART 1 - Creating a Class ==
:The class that is written in Python can contain variables, functions, code, but non none of the code is executed or run until the class is used to create the object. Remember that the class is a blueprint for how your object will work, the object that will be created is what will actually be running the code. This of a class in the same way as a function definition, the function doesn't run until it's executed, code inside classes don't run until the are made into objects.
:'''Perform the Following Steps:'''
print('GPA of student ' + self.name + ' is ' + str(gpa / len(self.courses)))
</source>
:# This is the Student class, with this class multiple Student objects can be created. There are a number of parts of this script that should look familiar, such as functions, for loops, variables. Functions indented underneath the class definition are called methods. Variables starting with '''self.''' are called public attributes. In the next steps lets break down this class and explain each part in detail.
== PART 2 - Understanding Class Structure ==