Lesson 31 of 34

Classes & Objects: உங்கள் சொந்த data type

10 min 35 XP

class என்பது ஒரு வரைபடம் (blueprint). அதிலிருந்து உருவாக்கப்படும் ஒவ்வொன்றும் ஒரு object. உதாரணம்: Student என்பது class; Arun, Priya என்பவை 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-க்குள் சேமிக்கிறது.

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.

Challenge

+35 XP

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

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