What is the __ str __ method used for quizlet?

Upgrade to remove ads

Only SGD 41.99/year

  1. Science
  2. Computer Science

  • Flashcards

  • Learn

  • Test

  • Match

  • Flashcards

  • Learn

  • Test

  • Match

Terms in this set (21)

Class

A "blueprint" or "template" for creating a particular type of object. It specifies the data attributes and methods for the object, accessed via dot notation.

Difference between Procedural Programming and Object Oriented Programming?

Procedural Programming is centred on creating procedures (functions) whilst Object Oriented Programming is centred on creating objects.

Encapsulation

Combining of data and code into a single object.

Data attributes

Data contained in an object.

Methods

Functions that perform operations on an object's data attributes.

Object

An instance of a class. It is a self contained unit consisting of data attributes and methods that operate on the data attributes.

Data hiding

An object's attributes may or may not be visible outside the class definition. Only the object's methods may directly access and make changes to the object's data attributes.

Protects from accidental corruption.

You need to name attributes with a double underscore prefix, and those attributes then are not be directly visible to outsiders.

Public methods

Those methods that can be accessed by entities outside the object.

Private methods

Those methods which are part of the object's internal workings and external entities do not have access to them. In Python this is done by adding 2 underscores characters ( __ ) in front of the name.

Class definition

Set of statements that define a class's methods and data attributes.

__init__ method

First method inside a a class definition. It is a special method, which is called class constructor or initialization method. It executes immediately after an object is created and initialises the object's data attributes.

e.g: def __init__(self, name, salary):
self.name = name
self.salary = salary

Self parameter

When a method is called, Python automatically passes a reference to the calling object into the first parameter (self, etc)

Modules

A module allows you to logically organize your Python code.

Grouping related code into a module makes the code easier to understand and use.

A module is a Python object with arbitrarily named attributes that you can bind and reference.

Creating Objects

To create instances of a class (objects), you call the class using class name and pass in whatever arguments its __init__ method accepts.

Accessing objects attributes

You access the object's attributes using the dot operator with object.

e.g: emp1.displayEmployee()

Garbage Collection

The process by which Python periodically reclaims blocks of memory that no longer are in use is termed Garbage Collection.

__str__ method

The str function converts any object to its string representation.

When the __str__ method is available, operations such as print automatically use it to obtain an object's string representation.

Instance Attributes

Belongs to the specific instance of the class (the object).

Each instance of a class will have its own set of attributes

Accessor

Methods that allow a user to observe but not change the state of an object.

GETTERS

Mutators

Methods that allow a user to modify an objects state.

SETTERS

Unified Modelling Language

Name:
___________________________________
Data Attributes Listed:
(Instance Variables)
____________________________________
Methods Listed:
(Mutators and Accessors)
____________________________________

Sets with similar terms

chapter 10 - classes and object-oriented programmi…

18 terms

icatugasud

ch20 python classes and object oriented programming

22 terms

reevesld01

OOP terminology

21 terms

busone390

Object Oriented Programming Terms

20 terms

crunch53

Other sets by this creator

Chapter 5 - Project Planning - Scope & WBS

35 terms

kboys03

Dictionaries, Lists and Strings

26 terms

kboys03

Verified questions

COMPUTER SCIENCE

An experimental addition to UNIX allows a user to connect a watchdog program to a file. The watchdog is invoked whenever a program requests access to the file. The watchdog then either grants or denies access to the file. Discuss two pros and two cons of using watchdogs for security.

Verified answer

COMPUTER SCIENCE

This built-in function returns the highest value in a list. a. minimumOf() b. minimum() c. min() d. least()

Verified answer

COMPUTER SCIENCE

A program contains the following function. int cube(int num) { return num * num * num; } Write a statement that passes the value 4 to this function and assigns its return value to the variable result.

Verified answer

COMPUTER SCIENCE

Prove that COUNTING-SORT is stable.

Verified answer

Recommended textbook solutions

What is the __ str __ method used for quizlet?

Fundamentals of Database Systems

7th EditionRamez Elmasri, Shamkant B. Navathe

687 solutions

What is the __ str __ method used for quizlet?

Starting Out with Python

4th EditionTony Gaddis

629 solutions

What is the __ str __ method used for quizlet?

Starting Out with C++ from Control Structures to Objects

8th EditionGodfrey Muganda, Judy Walters, Tony Gaddis

1,294 solutions

What is the __ str __ method used for quizlet?

Information Technology Project Management: Providing Measurable Organizational Value

5th EditionJack T. Marchewka

346 solutions

Other Quizlet sets

apes barrons ch 4

12 terms

amtedesco

CH.15-Biotechnology

36 terms

ksalazar7

South Asia

32 terms

abigailhammye21

Study Set 3: Anatomy and Physiology

27 terms

ahg714

Related questions

QUESTION

In applying algorithms, what do you need to show for your response 2c (row 5)?

5 answers

QUESTION

The major AI language for the period 1960 through the 1990s was

7 answers

QUESTION

Each language has a strict set of rules that must be strictly followed when writing a program. What is this set of rules called?

9 answers

QUESTION

Explain why Heath is using an array to store the data

4 answers

What is the purpose of the _ _init_ _ method when does it execute?

The __init__ method is the Python equivalent of the C++ constructor in an object-oriented approach. The __init__ function is called every time an object is created from a class. The __init__ method lets the class initialize the object's attributes and serves no other purpose. It is only used within classes.

What method is known as a class's constructor because it is run automatically?

A static constructor is called automatically. It initializes the class before the first instance is created or any static members declared in that class (not its base classes) are referenced. A static constructor runs before an instance constructor.

What is the purpose of the self parameter quizlet?

The self parameter is a reference to the current instance of the class, and is used to access variables that belongs to the class.

What is the name of the special method that is called when you create an instance of the class?

Constructor. The constructor method is a special method for creating and initializing an object created with a class . There can only be one special method with the name "constructor" in a class. A SyntaxError will be thrown if the class contains more than one occurrence of a constructor method.