I assumed sequence types in Python were value types. It turns out they're reference types (Meaning that the value of a variable won't be copied when assigned to a new variable, but referenced). So now I'm wondering, what are the value types in Python? That is, what types in Python can I assign to new variables without worrying that the variable was referenced?
The answer above is correct, but I object to the semantics of "reference".
C-like languages treat variables as fixed buckets, in which values are placed. When you call a function, a new set of buckets are created, and the values are copied into them. Sometimes, a bucket is pass-by-reference, and actually becomes an alias for the caller's bucket.
Python, on the other hand, treats variables as mere labels (names) for values (objects). When you call a function, a new set of labels are created and slapped onto those same objects.
It doesn't make sense to mention "references" in the context of Python, because in every other language, "reference" implies an alternative to "value". Python has no such duality; it just passes around and assigns objects. Nothing is referred to.
Nitpicky, perhaps, but the terminology causes no end of confusion for C++ programmers, who e.g. hear Python passes by references and don't understand how to reassign the caller's names.
Python passes by value, but the values are references.
That's silly. The passed values aren't references to objects; they ARE objects.
Perhaps this article (bit.ly/4Cjmn0) and the SO question that linked to it (bit.ly/3fRXW) can shed some light on this. I find the terminology used in the article helps makes things a bit less confusing. Also, while I see your point about references, I disagree with it. A label or name is a reference, in the general sense of the word. When I use your name, I am referring to you.
All values in Python are references. What you need to worry about is if a type is mutable. The basic numeric and string types, as well as tuple and frozenset are immutable; names that are bound to an object of one of those types can only be rebound, not mutated.
For completeness, could you add how I would go about duplicating/cloning a value?
That depends on the type. For lists, you can either pass it to list() or slice the whole thing (L[:]). For sets, pass it to set(). For other types, see the relevant documentation. Note that there are types that effectively cannot be cloned at all, simply because they represent an external resource (e.g. socket).
[SOLVED] Proper way to declare custom exceptions in modern Python?