100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Computer Science 144 3.2 summary

Rating
-
Sold
-
Pages
4
Uploaded on
28-09-2023
Written in
2023/2024

Detailed summary of chapter 3.2 - creating data types in Python. Includes everything you need to know about chapter 3.2 for the A1

Institution
Course








Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Course

Document information

Summarized whole book?
No
Which chapters are summarized?
Unknown
Uploaded on
September 28, 2023
Number of pages
4
Written in
2023/2024
Type
Summary

Subjects

Content preview

3.2 CREATING DATA TYPES

Introduction:
Data abstraction = the process of defining a data type
Another mantra: whenever you can clearly separate data and associated operations within
computation, you should do so

Basic elements of a data type:
API:
The application programming interface is the contract with all clients and, therefore, the
starting point for any implementation.
When creating a new data type for some application, the first step is to develop an API = a
design activity.
It is a good idea to compose some client code before finalizing the API.
Second step to creating a data type -> implement a Python class that meets the API
specifications.
Third step: compose a test client, to validate and test the design decisions made in the first
two steps.
Purpose of API: to separate clients from implementation.

Class:
We implement a data type as a class and name it with the same name as the class but with a
lowercase and followed by the .py extension.
3 key features of a data type (all different types of methods):
- A constructor
- Instance variables
- Methods


Constructor:
-> creates an objects of the specified type and returns a reference to that object.
Each data type defines a special method __init__() whose purpose is to define and initialise
the instance variables.
The first parameter in the constructor(__init__() method) is named self, followed by ordinary
parameter variables; the remaining lines make up the body of the constructor. The value of
the self parameter variable when __init()__ is invoked is a reference to the newly created
object

Instance variables:
-> implement the values and belong to a
particular instance of a class
Define and initialise each instance variable of the
newly created object in the constructor.
Instance variables start with an underscore.

Methods:
$4.29
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
jaidendutoit

Also available in package deal

Get to know the seller

Seller avatar
jaidendutoit Stellenbosch University
Follow You need to be logged in order to follow users or courses
Sold
5
Member since
2 year
Number of followers
2
Documents
14
Last sold
1 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions