Quantcast
Channel: Add variables to tuple - Stack Overflow
Viewing all articles
Browse latest Browse all 10

Answer by ehontz for Add variables to tuple

$
0
0

Another tactic not yet mentioned is using appending to a list, and then converting the list to a tuple at the end:

mylist = []for x in range(5):    mylist.append(x)mytuple = tuple(mylist)print mytuple

returns

(0, 1, 2, 3, 4)

I sometimes use this when I have to pass a tuple as a function argument, which is often necessary for the numpy functions.


Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>