Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Python Made Easy

You're reading from   Python Made Easy A First Course in Computer Programming Using Python

Arrow left icon
Product type Paperback
Published in Aug 2024
Publisher Packt
ISBN-13 9781836646150
Length 256 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Kevin Wilson Kevin Wilson
Author Profile Icon Kevin Wilson
Kevin Wilson
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

1. About The Author
2. Acknowledgements FREE CHAPTER
3. Getting Started 4. Python Basics 5. Data Structures 6. File Handling 7. Python Functions 8. Exception Handling 9. Object Oriented Programming 10. Modules & Libraries 11. Graphics and GUIs 12. Turtle Graphics 13. Game Development 14. Debugging and Testing 15. Deploying Apps 16. Web Development 17. Video Resources

Classes & Objects

A class is a blueprint for creating objects. It defines the attributes (data) and methods (behaviors) that the objects of that class will use.

Defining a Class

To define a class, you use the class keyword followed by the class name.

class MyClass:

    # Class attributes and methods go here

For example, here we’ve defined a class called Person with attributes and methods.

First, we create a new class named “Person”.

class Person:

Adding Attributes

Next, we define the attributes the class will use. To do this, we use the __init__() method. This is a special method called a constructor and is executed automatically when a new object of the class is created.

    def __init__(self, name, age):

        self.name = name

        self.age = age

The self parameter refers to the instance...

lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Python Made Easy
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon