---------- Forwarded message ---------- From: *diliup gabadamudalige* <dili...@gmail.com> Date: Sunday, May 25, 2014 Subject: [Tutor] class to function To: Danny Yoo <d...@hashcollision.org>
Is it wrong to say that __init__() is to initialize all the conditions you setupin the class? That's how i see it. I give below the way I see a class and it's workings. Please Correct if any mistakes. Say you have a class for a Spaceship Class Spaceship(): under the def __init__(): you set up all the details you want the spaceship to have. For example, self.engine=100 self. guns=100 self.shield=250 self.life=5 self if the Spaceship which will be built using the details given under the init in the Class Spaceship. So a class is a blu print to build the space ship and the init function contains all the things the space ship will contain. Now when you want a ne space ship say a RED one you can call the class with RedShip=Spaceship() and you can now giv e a new character to the space ship. A colour! like this RedShip.colour=Red Now along with the RedShip.enging=100 RedShip.guns=100 RedShip.shield=250 RedShip.life=5 the RedShip also has a NEW ATTRIBUTE. Colour. RedShip.colour=Red The def__init__() can also be setup so that you can give all the attributes its values like this. def__init__(power,bullets,energy,life) RedShip.enging=power RedShip.guns=bullets RedShip.shield=energy RedShip.life=life this way each ship can have different attributes. But they are all Spaceships. On Mon, May 26, 2014 at 6:38 AM, Danny Yoo <d...@hashcollision.org<javascript:_e(%7B%7D,'cvml','d...@hashcollision.org');> > wrote: > > i am trying to understand this code: > > http://nbviewer.ipython.org/gist/BenLangmead/6665861 > > I'm slightly familiar with the purpose of the code. It's constructing > a Suffix Tree, though not in linear time. > > Reading the code... ah. I see. This is enumerating through all > suffixes, and building it by repeated insertion into a trie. > > http://en.wikipedia.org/wiki/Trie > > The classes are used here to represent structured data and operations > to be performed on that structured data. The code fundamentally has a > structured value called a Node, with two fields to represent the > string label and the links to other nodes. > > > > Aside: there is a very good book by Dan Gusfield that talks about > suffix trees and how to construct them called "Algorithms on Strings, > Trees and Sequences: Computer Science and Computational Biology" > > > http://www.amazon.com/Algorithms-Strings-Trees-Sequences-Computational/dp/0521585198 > > which you may want to look at if you're interested in these algorithms. > > > It is probably not a good idea to try to intermix trying to understand > an algorithm like this at the same time as you're learning basic > features in your programming language. Consider a slightly simpler > example to learn about "classes", apart from the algorithms you are > studying. Most good Python tutorials should cover how to use classes > to build structured data and manipulate it. Alan Gauld's Python > tutorial, for example, should have a section on this. > > http://www.alan-g.me.uk/tutor/tutclass.htm > _______________________________________________ > Tutor maillist - > Tutor@python.org<javascript:_e(%7B%7D,'cvml','Tutor@python.org');> > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Diliup Gabadamudalige http://www.diliupg.com http://soft.diliupg.com/ ********************************************************************************************** This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. **********************************************************************************************
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor