Skip to content
Advertisement

Tag: tuples

Convert list to tuple in Python [duplicate]

This question already has answers here: Why does code like `str = str(…)` cause a TypeError, but only the second time? (20 answers) Closed 7 days ago. I’m trying to convert a list to a tuple. Most solutions on Google offer the following code: However, the code results in an error message when I run it: TypeError: ‘tuple’ object is

How does Python’s comma operator work during assignment?

I was reading the assignment statements in the Python docs ( http://docs.python.org/reference/simple_stmts.html#assignment-statements). In that it is quoted that: If the target is a target list enclosed in parentheses or in square brackets: The object must be an iterable with the same number of items as there are targets in the target list, and its items are assigned, from left to

How to change values in a tuple?

I have a tuple called values which contains the following: I want to change the first value (i.e., 275) in this tuple but I understand that tuples are immutable so values[0] = 200 will not work. How can I achieve this? Answer It’s possible via: But if you’re going to need to change things, you probably are better off keeping

Add variables to tuple

I am creating a database connection. While trying to add to the DB, I am thinking of creating tuples out of information and then add them to the DB. I am taking information from the user and store it in variables. Can I add these variables into a tuple? Can you please help me with the syntax? I only need

Subtracting 2 lists in Python

Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like Should I use tuples? If none of them defines these operands on these types, can I define it instead? If not, should I create a new vector3 class? Answer If this is something you end up doing frequently,

Advertisement