SCOUG Logo


Next Meeting: Sat, TBD
Meeting Directions


Be a Member
Join SCOUG

Navigation:


Help with Searching

20 Most Recent Documents
Search Archives
Index by date, title, author, category.


Features:

Mr. Know-It-All
Ink
Download!










SCOUG:

Home

Email Lists

SIGs (Internet, General Interest, Programming, Network, more..)

Online Chats

Business

Past Presentations

Credits

Submissions

Contact SCOUG

Copyright SCOUG



warp expowest
Pictures from Sept. 1999

The views expressed in articles on this site are those of their authors.

warptech
SCOUG was there!


Copyright 1998-2024, Southern California OS/2 User Group. ALL RIGHTS RESERVED.

SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group. OS/2, Workplace Shell, and IBM are registered trademarks of International Business Machines Corporation. All other trademarks remain the property of their respective owners.

The Southern California OS/2 User Group
USA

SCOUG-Programming Mailing List Archives

Return to [ 13 | April | 2005 ]

<< Previous Message << >> Next Message >>


Date: Wed, 13 Apr 2005 22:28:48 PDT7
From: Sheridan George <s-geo@usa.net >
Reply-To: scoug-programming@scoug.com
To: scoug-programming@scoug.com
Subject: SCOUG-Programming: Progress--Step 3

Content Type: text/plain

Lynn H. Maxson wrote:
> Peter,
>

>
> We have had two very excellent presentations by Greg Smith
> and Sheridan George on PERL. PERL has two forms of a list

Err...this should be Python. PERL is what you throw before swine.

> aggregate, one variable form and one constant form. Each
> looks the same except for boundary notation: (....) variable
> and [....] constant (if I have that right). Now I find the idea of

I need to tweek your understanding a little. Python tuples ( boundary notation (.....) ) are not
constant. They are immutable though it says in fine print. However, Python does have methods to
change a tuple. Under the covers it creates a new tuple and garbage collects the former one.

For example:
>>> x=(123,"abc") #create a tuple
>>> print type(x)

>>> x=x+("gfd",9876) #add a tuple to an immutable tuple
>>> print x
(123, 'abc', 'gfd', 9876) #worked OK
>>> print x[2] #pick one element of the tuple - the Python term is slice
gfd
>>> x[2]=('zxc',768) #try to change that element
Traceback (most recent call last):
File "", line 1, in ?
TypeError: object doesn't support item assignment

So, we see tuples are changeable (by method but not assignment) even though they are said to be
immutable.

Now for lists ( boundary notation [.....] ):
>>> a=[123, "abc"] #create a list
>>> print type(a)

>>> a=a+['tre',987] #add to list
>>> print a
[123, 'abc', 'tre', 987]
>>> print a[2] #pick an element
tre
>>> a[2]=921 #change an element by assignment
>>> print a
[123, 'abc', 921, 987] #works

Python lists are considered mutable.

The immutable constructs are required internally because they can be safely hashed. The Python
dictionary (a {key:value} pair) uses a hash for its key part. Dictionaries are the underpinnings of
Python. They are used for stacks and Name Space. Every time a class or function is defined a new
dictionary is created. That dictionary holds all of the internals for that class or function. And
as I understand it when a class is instantiated yet another dictionary is created.


>
> In short I don't believe in a list constant or the need for it. If
> you want something constant, you don't change it. So it

This is how Python works. Python does not have a constant construct. If you want a constant simply
don't change it. The convention is to all caps the var name to indicate it is to be considered a
constant. e.g. CONSTANT = 12345

Sheridan

=====================================================

To unsubscribe from this list, send an email message
to "steward@scoug.com". In the body of the message,
put the command "unsubscribe scoug-programming".

For problems, contact the list owner at
"postmaster@scoug.com".

=====================================================


<< Previous Message << >> Next Message >>

Return to [ 13 | April | 2005 ]



The Southern California OS/2 User Group
P.O. Box 26904
Santa Ana, CA 92799-6904, USA

Copyright 2001 the Southern California OS/2 User Group. ALL RIGHTS RESERVED.

SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group. OS/2, Workplace Shell, and IBM are registered trademarks of International Business Machines Corporation. All other trademarks remain the property of their respective owners.