473,785 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on Standard Types

Hi,

I'm quite new to Python and I am reading this book called 'Core Python
Programming' by Wesley J. Chun. I think that this is not a new book but
I believe some of the points are still valid.

There is this part in the book where it says:

"In Python, standard types are not classes, so creating integers and
strings does not involve instantiation".

But later in the book, it talks about 'numeric objects' created when a
numeric literal is assigned to a reference.

So my question now is, if standard types are objects, shouldn't they
have classes as well ? Isn't it that a class is the blueprint of an
object? If they don't have a class to begin with, how are these objects
created?

Thanks.
Al

Jul 18 '05 #1
4 1639

"hostmaster " <al***@mylinuxs ite.com> wrote in message
news:ma******** *************** ***********@pyt hon.org...
Hi,

I'm quite new to Python and I am reading this book called 'Core Python
Programming' by Wesley J. Chun. I think that this is not a new book but
I believe some of the points are still valid.

There is this part in the book where it says:

"In Python, standard types are not classes, so creating integers and
strings does not involve instantiation".

But later in the book, it talks about 'numeric objects' created when a
numeric literal is assigned to a reference.

So my question now is, if standard types are objects, shouldn't they
have classes as well ? Isn't it that a class is the blueprint of an
object? If they don't have a class to begin with, how are these objects
created?
He's trying to make a fairly subtle point. At least, it's subtle until
you get into the nuts and bolts.

The point is that class instances are a single type, regardless of
the class. So while it's perfectly true to say what he did, it has
very little practical meaning unless you attempt to do an operation
on, say, an integer that depends on something that's unique to
an instance.

John Roth


Thanks.
Al

Jul 18 '05 #2
In article <ma************ *************** *******@python. org>,
hostmaster <al***@mylinuxs ite.com> wrote:

I'm quite new to Python and I am reading this book called 'Core Python
Programming' by Wesley J. Chun. I think that this is not a new book but
I believe some of the points are still valid.

There is this part in the book where it says:

"In Python, standard types are not classes, so creating integers and
strings does not involve instantiation".


Actually, this bit *is* definitely out of date; Python 2.2 introduced
new-style classes, and all the standard types are now new-style classes.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

This is Python. We don't care much about theory, except where it intersects
with useful practice. --Aahz
Jul 18 '05 #3
On Sun, 7 Sep 2003 13:18:57 -0400, "John Roth" <ne********@jhr othjr.com> wrote:

"hostmaster " <al***@mylinuxs ite.com> wrote in message
news:ma******* *************** ************@py thon.org...
Hi,

I'm quite new to Python and I am reading this book called 'Core Python
Programming' by Wesley J. Chun. I think that this is not a new book but
I believe some of the points are still valid.

There is this part in the book where it says:

"In Python, standard types are not classes, so creating integers and
strings does not involve instantiation". I think that is out of date.

But later in the book, it talks about 'numeric objects' created when a
numeric literal is assigned to a reference.

So my question now is, if standard types are objects, shouldn't they
have classes as well ? Isn't it that a class is the blueprint of an
object? If they don't have a class to begin with, how are these objects
created?
By "standard types" you mean int and str etc.? Try interactive help for sume suggestive info:
help(int) Help on class int in module __builtin__:

class int(object)
| int(x[, base]) -> integer
|
| Convert a string or number to an integer, if possible. A floating point
| argument will be truncated towards zero (this does not include a string
| representation of a floating point number!) When converting a string, use
| the optional base. It is an error to supply a base when converting a
| non-string. If the argument is outside the integer range a long object
| will be returned instead.
|
| Methods defined here:
|
| __abs__(...)
| x.__abs__() <==> abs(x)
|
| __add__(...)
| x.__add__(y) <==> x+y
|

...
(etc.)
help(str)

Help on class str in module __builtin__:

class str(basestring)
| str(object) -> string
|
| Return a nice string representation of the object.
| If the argument is a string, the return value is the same object.
|
| Method resolution order:
| str
| basestring
| object
|
| Methods defined here:
|
| __add__(...)
| x.__add__(y) <==> x+y

...
(etc.)

He's trying to make a fairly subtle point. At least, it's subtle until
you get into the nuts and bolts.

The point is that class instances are a single type, regardless of You don't mean instances of classes are a single type, I assume. You mean
classes themselves are instances of a single type class, right?
(Except old-style classes, which are of type classobj).
the class. So while it's perfectly true to say what he did, it has I don't know how you are reading it. It seems out of date to me.
very little practical meaning unless you attempt to do an operation
on, say, an integer that depends on something that's unique to
an instance.


You can now subclass int and str etc., which has real and practical meaning though.
And it's a pretty strong indication that int and str are classes of some kind ;-)

Regards,
Bengt Richter
Jul 18 '05 #4
aa**@pythoncraf t.com (Aahz) writes:
"In Python, standard types are not classes, so creating integers and
strings does not involve instantiation".


Actually, this bit *is* definitely out of date; Python 2.2 introduced
new-style classes, and all the standard types are now new-style classes.


The statement was always incorrect. The standard types always involved
instantiation, and integers and strings have always been objects, with
a separate identity. Whether or not they had a relation ship <type
'classobj'> is irrelevant for that.

Regards,
Martin
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2269
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
10
2098
by: Suki | last post by:
Hi, I'm writing a templated class, and i dont want to use the class otherthan for some predetermined types, say, int, double etc. This class has no meaning for typenames other than those few. ========================= template <class T> myClass {....} ;
18
3047
by: David Buchan | last post by:
Hi guys, This may be a dumb question; I'm just getting into C language here. I wrote a program to unpack a binary file and write out the contents to a new file as a list of unsigned integers. It works on an IBM mainframe under AIX with GCC, but has trouble on Intel with GCC (DJGPP). I think it's an endian problem. The trouble is, although most values in the extracted list are correct,
7
2623
by: Gustavo L. Fabro | last post by:
Greetings! Some classes that once compiled without problems on VS 2003 have now problems on VS 2005 Beta 1. I'm talking about a __nogc class that is exported with __declspec(dllexport). The compiler message is this: VCSelectLibraryForm.cpp ...\Forms\QiForm.h(48) : error C3395: 'TQiForm::GetDotNetMouseButton' :
38
2519
by: Till Crueger | last post by:
Hi, I stumbled upon the following code to determine byte ordering in the FAQ: union { int i; char c; } x; /* do stuff */
18
2140
by: Giannis Papadopoulos | last post by:
According to the standard (ISO C99 draft WG14/N1124), void is the incomplete type that cannot be completed and comprises the empty set of values. Since it declares the absense of a value can it be considered a data type? Regarding void*, is it just a simple reuse of the same keyword (void) or they have a closer relationship? I could think of only one - a pointer to an incomplete type. However, if one could say that void is the absense...
25
2266
by: Why Tea | last post by:
Thanks to those who have answered my original question. I thought I understood the answer and set out to write some code to prove my understanding. The code was written without any error checking. --- #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct {
17
2328
by: Ben Bacarisse | last post by:
candide <toto@free.frwrites: These two statements are very different. The first one is just wrong and I am pretty sure you did not mean to suggest that. There is no object in C that is the same as its address. The second one simply depends on a term that is not well-defined. Most people consider the type to be an important part of the notion of
28
1825
by: junky_fellow | last post by:
Guys, Consider a function func(void **var) { /* In function I need to typecast the variable var as (int **) I mean to say, I need to access var as (int **) }
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.