Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Introduction to python

Rating
-
Sold
-
Pages
23
Uploaded on
08-04-2025
Written in
2023/2024

This PDF contains comprehensive notes covering the fundamental concepts of Python programming. It is designed for beginners who are new to coding or looking to build a strong foundation in Python. The notes are organized in a clear and structured format, making them ideal for self-study, classroom learning, or quick reference.

Show more Read less
Institution
Course

Content preview

Python Application Programming (15CS664) Module IV



MODULE IV


4.1 CLASSES AND OBJECTS
Programmer defined types, Attributes, Rectangles, Copying, Debugging
4.2 CLASSES AND FUNCTIONS
Time, Pure Functions, Modifiers, Prototyping vs Planning, Debugging
4.3 CLASSES AND METHODS
Object Oriented Features, The init Method and str Method, Operator Overloading, Type-based dispatch,
Polymorphism, Interface and Implementation, Debugging




Mamatha A, Asst Prof, Dept of CSE, SVIT Page 1

,Python Application Programming (15CS664) Module IV


MODULE IV

4.1 CLASSES AND OBJECTS
 Python is an object-oriented programming language, and class is a basis for any object oriented
programming language.
 Class is a user-defined data type which binds data and functions together into single entity.
 Class is just a prototype (or a logical entity/blue print) which will not consume any memory.
 An object is an instance of a class and it has physical existence.
 One can create any number of objects for a class.
 A class can have a set of variables (also known as attributes, member variables) and member
functions (also known as methods).

 Programmer-defined Types
 A class in Python can be created using a keyword class.
 Here, we are creating an empty class without any members by just using the keyword passwithin it.

class Point:
pass

print(Point)

The output would be –
<class ' main .Point'>

 The term main indicates that the class Point is in the main scope of the current module.
 In other words, this class is at the top level while executing the program.
 Now, a user-defined data type Point got created, and this can be used to create any number of
objects of this class.
 Observe the following statements:

p=Point()

 Now, a reference (for easy understanding, treat reference as a pointer) to Point object is created
and is returned. This returned reference is assigned to the object p.
 The process of creating a new object is called as instantiation and the object is instance of a
class.
 When we print an object, Python tells which class it belongs to and where it is stored in the
memory.
print(p)

The output would be –
< main .Point object at 0x003C1BF0>




Mamatha A, Asst Prof, Dept of CSE, SVIT Page 2

, Python Application Programming (15CS664) Module IV


 The output displays the address (in hexadecimal format) of the object in the memory.
 It is now clear that, the object occupies the physical space, whereas the class does not.

 Attributes
 An object can contain named elements known as attributes.
 One can assign values to these attributes using dot operator.
 For example, keeping coordinate points in mind, we can assign two attributes x and y for the
object of a class Point as below

p.x =10.0
p.y =20.0

 A state diagram that shows an object and its attributes is called as object diagram.
 For the object p, the object diagram is shown in Figure below.
Point
x 10.0
p 20.0
y


Figure : Object Diagram

 The diagram indicates that a variable (i.e. object) p refers to a Point object, which contains two
attributes.
 Each attributes refers to a floating point number.
 One can access attributes of an object as shown –

>>> print(p.x)
10.0
>>> print(p.y)
20.0

 Here, p.x means “Go to the object p refers to and get the value of x”.
 Attributes of an object can be assigned to other variables

>>> x= p.x
>>> print(x)
10.0

 Here, the variable x is nothing to do with attribute x.
 There will not be any name conflict between normal program variable and attributes of an object.
 A complete program: Write a class Point representing a point on coordinate system. Implement
following functions –
 A function read_point() to receive x and y attributes of a Point object as user input.



Mamatha A, Asst Prof, Dept of CSE, SVIT Page 2

Written for

Course

Document information

Uploaded on
April 8, 2025
Number of pages
23
Written in
2023/2024
Type
Class notes
Professor(s)
Bayregowda
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sanathmogaveer13

Also available in package deal

Get to know the seller

Seller avatar
sanathmogaveer13 VTU
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
5
Last sold
-

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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions