• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 1 fuera de 4 páginas
Resumen

Computer Science 144 3.2 summary

Document preview thumbnail
Vista previa 1 fuera de 4 páginas

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

Vista previa del contenido

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:

Libro relacionado
 image
Robert Sedgewick, Kevin Wayne, Robert Dondero Introduction to Programming in Python
Editorial: 2015 ISBN: 9780134076522 Edición: Desconocido

Información del documento

¿Un libro?
No
¿Qué capítulos están resumidos?
Desconocido
Subido en
28 de septiembre de 2023
Número de páginas
4
Escrito en
2023/2024
Tipo
Resumen
$4.36

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
6
Seguidores
2
Artículos
14
Última venta
3 meses hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes