Built-In Functions - University of Washington
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 str() len() abs()
Class Method __str__() __len__() __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
- python function basics introduction shippensburg university school
- draw template on preconditions how do functions work
- ppyytthhoonn ffuunnccttiioonnss
- transfer functions with python
- functions in python department of computer science and electrical
- worksheet functions
- working with functions
- python working with pixels villanova
- s python cheat sheet data science free
- function programming in python
Related searches
- university of washington hr jobs
- university of washington jobs listing
- university of washington human resources
- university of washington human resources dept
- university of washington baseball roster
- university of washington product management
- university of washington online mba
- university of washington printable map
- university of washington opioid taper
- university of washington opioid calculator
- university of washington program management
- university of washington graduate programs