Lesson 31 of 34

Classes & Objects: உங்கள் சொந்த data typeClasses & Objects: Your Own Data Types

10 min 35 XP

class என்பது ஒரு வரைபடம் (blueprint). அதிலிருந்து உருவாக்கப்படும் ஒவ்வொன்றும் ஒரு object. உதாரணம்: Student என்பது class; Arun, Priya என்பவை objects.

A class is a blueprint. Each thing made from it is an object. Example: Student is the class; Arun and Priya are objects.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

__init__ என்பது object உருவாகும் போது தானாக இயங்கும். self என்பது “இந்த object” என்று பொருள். self.name = name என்பது பெயரை object-க்குள் சேமிக்கிறது.

__init__ runs automatically when an object is created. self means “this object”. self.name = name stores the name inside the object.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

class பெயர்களை பெரிய எழுத்தில் தொடங்குவது Python வழக்கம்: Student, BankAccount.

By convention, class names start with a capital letter: Student, BankAccount.

Challenge

+35 XP

Book என்ற class எழுதுங்கள். __init__ மூலம் title மற்றும் price ஆகியவற்றைச் சேமிக்க வேண்டும். Book("Python Basics", 350) உருவாக்கி, அதன் title மற்றும் price-ஐ ஒரே வரியில் print செய்யுங்கள்.

Write a class Book whose __init__ stores title and price. Create Book("Python Basics", 350) and print its title and price on one line.

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.