A constructor is special class method that is used to initialize objects. In Python, a constructor method uses the special function name __init__().
- [Announcer] An instance of a class is called an object.…It's creating by calling the class…itself as if it were a function.…Here in Komodo, I've opened a working copy…of constructor.py from chapter nine of the exercise files,…and, I'm going to close this bottom pane for a moment,…and if we come down here to the bottom,…you see down here in main, I create two objects,…a0 and a1 from the animal class.…And I'm initializing it with various parameters.…Type of the animal, the name of the animal,…and the sound that it makes.…
I'm also simply calling "print animal",…so "print animal" is this function here…that expects an animal object and prints the animal.…And I'm calling it directly here from the constructor.…From the class, without creating an intermediary object.…This works exactly the same way because if you'll remember,…function parameters work exactly like assignments in Python.…And so when I run this, you see I get three animals,…a kitten named Fluffy that says "rwar",…and if we scroll down here you can see that.…
- 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 Efficiently (2017)with 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.