I'm completely new to programming. I am using vscode and have python 3.10.5,I am following no starch press crash course in python (2nd edition) and in the section on lists it tells me that a list in python is written between square brackets, separated by commas, like the following:
list1 = ['a', 'b', 'c'] When I print this I get back the square brackets and the stuff inside, which is all fine. I was playing around and wrote the following (expecting an error)
list2 = 'a', 'b', 'c' But when I print this, instead of an error I get back the right hand side but inside of round brackets.
What type of thing have I defined in list2?
print(type(list2))and you'll see it's atuple. If you haven't done so yet and you're sticking with Python, I'd recommend going through the Python tutorial.tupleis like a list except that you can't change it after its been created.(and)are used to group things. The commas make thetupleand the parens are only needed if the commas are ambiguous syntactically. Lets say I want to call a function with a tuple, but the function syntax also uses commas to separate parameters., I'd have to put the tuple in its own paren.