By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

Data types

P: n/a
What are the user defined types in Python? Can we call lists, tuples &
dictionaries user-defined data types?
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Lists, tuples, and dictionaries are built-in types.
Classes are the mechanism for user-defined types in Python.

Jul 18 '05 #2

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

Jul 18 '05 #3

P: n/a
On 24 Mar 2005 10:29:40 -0800, va******@yahoo.com <va******@yahoo.com> 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
Jul 18 '05 #4

P: n/a
va******@yahoo.com 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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.