Skip to content

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 ru…

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 pro…

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 f…