P. 1
Python 3: Byte of Python

Python 3: Byte of Python


|Views: 3,310|Likes:
Published by eebeta
a very good book to learn Python as a beginner, from http://www.swaroopch.com/notes/Python
a very good book to learn Python as a beginner, from http://www.swaroopch.com/notes/Python

More info:

Published by: eebeta on Feb 12, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF or read online from Scribd
See more
See less



The repr function is used to obtain a canonical string representation of the object. The
interesting part is that you will have eval(repr(object)) == object most of the time.

>>> i = []
>>> i.append('item')
>>> repr(i)
>>> eval(repr(i))
>>> eval(repr(i)) == i

Python en:More


Basically, the repr function is used to obtain a printable representation of the object. You
can control what your classes return for the repr function by defining the __repr__
method in your class.


We have covered some more features of Python in this chapter and yet we haven't covered
all the features of Python. However, at this stage, we have covered most of what you are
ever going to use in practice. This is sufficient for you to get started with whatever
programs you are going to create.
Next, we will discuss how to explore Python further.

Previous Next

External links

[1]http:/ / docs.python.org/ dev/ 3.0/ reference/ datamodel.html#special-method-names

Source: http:/ / www.swaroopch.com/ mediawiki/ index.php?title=Python_
Principal Authors: Swaroop

Python en:What Next

If you have read this book thoroughly till now and practiced writing a lot of programs, then
you must have become comfortable and familiar with Python. You have probably created
some Python programs to try out stuff and to exercise your Python skills as well. If you have
not done it already, you should. The question now is 'What Next?'.
I would suggest that you tackle this problem:
Create your own command-line address-book program using which you can add,
modify, delete or search for your contacts such as friends, family and colleagues
and their information such as email address and/or phone number. Details must
be stored for later retrieval.
This is fairly easy if you think about it in terms of all the various stuff that we have come
across till now. If you still want directions on how to proceed, then here's a hint.

Hint (Don't read)

Create a class to represent the person's information. Use a dictionary to store person
objects with their name as the key. Use the pickle module to store the objects
persistently on your hard disk. Use the dictionary built-in methods to add, delete and
modify the persons.
Once you are able to do this, you can claim to be a Python programmer. Now, immediately
send me a mail [1]

thanking me for this great book ;-) . This step is optional but
recommended. Also, please consider making a donation, contributing improvements or
volunteering translations to support the continued development of this book.
If you found that program easy, here's another one:

Python en:What Next


Implement the replace command [2]

. This command will replace one string with

another in the list of files provided.
The replace command can be as simple or as sophisticated as you wish, from simple string
substitution to looking for patterns (regular expressions).
After that, here are some ways to continue your journey with Python:

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->