[Tutor] Java style assignments in Python

Alexandre Ratti alex at gabuzomeu.net
Thu Sep 11 18:41:17 EDT 2003


Hello,


tpc at csua.berkeley.edu wrote:
> hello all, I was curious if there is a way to implement Java style
> assignments in Python.  Let's say I have a block of code:

  > list_A, list_B, list_C = []
> 
> Is there any way to do this without generating an error:

As explained by other posters, you need to type:

	list_A, list_B, list_C = [], [], []

You could also build you own constructor:

##
 >>> def lists(n):
... 	l = [[] for x in range(n)]
... 	return tuple(l)

 >>> list_A, list_B, list_C = lists(3)
 >>> list_A.append('titi')
 >>> list_A
['titi']
 >>> list_B
[]
##


Cheers.

Alexandre







More information about the Tutor mailing list