Overloading of operators on standard objects in Python
In python, everything is an object and operations performed by operators such as + and * vary in exactly what they do based on the class (type) or objects on which they're run.
If I use the * operator on a list, it replicates it ... but if I use it on an integer, it multiplies it ...
apple = [17]
orange = 20
firstfruit = apple * 7
secondfruit = orange * 7
print firstfruit
print secondfruit
Results:
[17, 17, 17, 17, 17, 17, 17]
140
(written 2005-07-19 17:58:22)
Associated topics are indexed under Y104 - Python - Lists and Tuples Y112 - Python - Objects - Intermediate
Some other Articles
Training course plans for 2006 What is a callback? Feast or famine Managing conflict and disappointment Overloading of operators on standard objects in Python Central London Courses - Perl, PHP, Python, Tcl, MySQL Exceptions in Python Bridging to the customer requirement Getting the lighting right A word of admiration for the London cabbie
1638 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|