After reading lesson 33, you’ll be able to
- Add special Python methods to your classes
- Use special operators such as +, -, /, and * on your classes
You’ve been working with classes defined in the Python language since you wrote your first Python program. The most basic type of objects in the Python language, called built-in types, allowed you to use special operators on these types. For example, you used the + operator between two numbers. You were able to use the [] operator to index into a string or a list. You were able to use the print() statement on any of these types of objects, as well as on lists and dictionaries.
Consider this
- Name five operations you can do between integers.
- Name one operation you can do between two strings.
- Name one operation you can do between a string and an integer.
Answer:
- +, -, *, /, %
- +
- *
Each of these operations is represented in shorthand using a symbol. However, the symbol is only a shorthand notation. Each operation is actually a method that you can define to work with an object of a specific type.