Quantcast
Viewing latest article 3
Browse Latest Browse All 10

Answer by ehontz for Add variables to tuple

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 latest article 3
Browse Latest Browse All 10

Trending Articles



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