Data types

Discussion in 'Python' started by waqar, Mar 24, 2005.

  1. waqar

    waqar Guest

    What are the user defined types in Python? Can we call lists, tuples &
    dictionaries user-defined data types?
     
    waqar, Mar 24, 2005
    #1
    1. Advertising

  2. Lists, tuples, and dictionaries are built-in types.
    Classes are the mechanism for user-defined types in Python.
     
    Lonnie Princehouse, Mar 24, 2005
    #2
    1. Advertising

  3. waqar

    Guest

    I am new to python and learning it. Can you please give me a simple
    example of user defined type through class mechanism.
     
    , Mar 24, 2005
    #3
  4. waqar

    Bill Mill Guest

    On 24 Mar 2005 10:29:40 -0800, <> wrote:
    > I am new to python and learning it. Can you please give me a simple
    > example of user defined type through class mechanism.


    GIYF:
    http://www.python.org/2.2/descrintro.html#subclassing

    Peace
    Bill Mill
    bill.mill at gmail.com
     
    Bill Mill, Mar 24, 2005
    #4
  5. waqar

    Tim Jarman Guest

    wrote:

    > I am new to python and learning it. Can you please give me a simple
    > example of user defined type through class mechanism.


    Python 2.4 (#1, Dec 31 2004, 17:21:43)
    [GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class Gumby(object):

    .... def __init__(self, body_part):
    .... self.body_part = body_part
    .... def speak(self):
    .... print "My %s hurts!" % self.body_part
    ....
    >>> g = Gumby("brain")
    >>> g

    <__main__.Gumby object at 0x402c570c>
    >>> g.speak()

    My brain hurts!


    Despite what Mr Gumby just said, defining your own classes is pretty
    painless in Python. Check out the Tutorial, especially section 9:
    http://www.python.org/doc/2.4/tut/node11.html

    Enjoy!

    --
    Website: www DOT jarmania FULLSTOP com
     
    Tim Jarman, Mar 24, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sathyaish
    Replies:
    2
    Views:
    590
    Sathyaish
    May 22, 2005
  2. Soren Kuula
    Replies:
    2
    Views:
    564
    Henry S. Thompson
    Dec 1, 2005
  3. ramu
    Replies:
    2
    Views:
    328
    rlblaster
    Feb 20, 2006
  4. Gary Roach
    Replies:
    0
    Views:
    114
    Gary Roach
    Sep 1, 2013
  5. Fábio Santos
    Replies:
    0
    Views:
    122
    Fábio Santos
    Sep 4, 2013
Loading...

Share This Page