Built-In Functions
Built-In Functions
Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides.
Except where otherwise noted, this work is licensed under:
Exceptions
raise type(message)
raise Exception(message)
Exceptions
AssertionError
TypeError
NameError
ValueError
IndexError
SyntaxError
ArithmeticError
2
__str__()
? We already know about the __str__() method that allows a
class to convert itself into a string
rectangle.py
1 class Rectangle:
2
def __init__(self, x, y, width, height):
3
self.x = x
4
self.y = y
5
self.width = width
6
def __str__(self):
7
return "(x=" + str(self.x) + ",y=" +
8
str(self.y) + ",w=" + str(self.width) +
9
",h=" + str(self.height) + ")"
3
Underscored methods
? There are many other underscored methods that allow the
built-in function of python to work
? Most of the time the underscored name matches the built-in
function name
Built-In
Class Method
str()
__str__()
len()
__len__()
abs()
__abs__()
4
First Class Citizens
? For built-in types like ints and strings we can use
operators like + and *.
? Our classes so far were forced to take back routes and use
methods like add() or remove()
? Python is super cool, in that it allows us to define the usual
operators for our class
? This brings our classes up to first class citizen status just
like the built in ones
5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- two kinds of map reduce programming in java python in pig
- functional programming with python cornell university
- lecture on mapreduce and spark asaf cidon
- map reduce tutorial rxjs ggplot2 python data
- built in functions
- advanced analysis of satellite imagery using python
- prof rob miller l15 map filter reduce
- functions in python
- lecture 09 filter map reduce and lambda
- distributed computing with spark and mapreduce
Related searches
- calculator built in windows 10
- vba built in function list
- access built in functions
- systemverilog built in functions
- r built in dataset
- bash shell built in commands
- verilog built in functions
- built in mean function python
- what is being built in my area
- toyotas built in usa
- python built in functions
- python built in types