It's easy to create classes in Python. In Python, a class is simply a container for data and functions. This lesson describes how to create a class in Python.
- [Instructor] A class is the basis of all data in Python,…everything is an object in Python,…and a class is how an object is defined.…Here in Komodo, I've opened a working copy of class.py,…from chapter nine of the exercises files,…and down here, beginning on line four…we see our class definition beginning…with the keyword class, and the name of the class,…and a colon, and then everything that defines the class…is indented under that declaration.…
We have data in the form of these variables,…and we have methods in the form…of these function definitions.…You'll notice that the first parameter…of a method is always self.…Self is not a keyword.…You can actually name that first parameter…whatever you want to, but self is traditional…and I highly recommend that you use self…so that as people are reading your code,…they know what you're talking about.…So the first argument is self,…which is a reference to the object,…not the class, to the object.…
And so, when an object is created from the class,…self will reference that object.…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.