New to Python

Paulo da Silva psdasilvaX at esotericaX.ptX
Mon Mar 12 08:19:35 EDT 2007


Alberto Vieira Ferreira Monteiro escreveu:
> Hi, I am new to Python, how stupid can be the questions I ask?
> 
> For example, how can I add (mathematically) two tuples?
> x = (1,2)
> y = (3,4)
> How can I get z = (1 + 3, 2 + 4) ?
> 
> Alberto Monteiro

I think that what you want is numpy.
I don't know too much about it but a possible solution is:

import numpy
x=numpy.array([1,2])
y=numpy.array([3,4])
z=x+y

Now z is an array containing 4,6.
You may convert it to list or tuple
z=list(z)




More information about the Python-list mailing list