像列表这样的数据结构的名称是什么,但在输出中带有圆括号?
What is the name of data structure like list, but with round brackets in output?
我有三个变量。我知道前两个的名字,但不知道最后一个。
代码:
somev1 = ['"Peter"','"20"'] # List
somev2 = ', '.join(somev1) # Just a string, that was joined from first list
somev3 = "Peter", "20" # I don't know
print(somev1) # Output : ['"Peter"', '"20"']
print(somev2) # Output : "Peter", "20"
print(somev3) # Output : ('Peter', '20')
somev3 = "Peter", "20"
创建一个 tuple
就像一个列表接受它是不可变的。
相当于:
somev3 = ("Peter", "20")
#or
somev3 = tuple(["Peter", "20"])
我有三个变量。我知道前两个的名字,但不知道最后一个。
代码:
somev1 = ['"Peter"','"20"'] # List
somev2 = ', '.join(somev1) # Just a string, that was joined from first list
somev3 = "Peter", "20" # I don't know
print(somev1) # Output : ['"Peter"', '"20"']
print(somev2) # Output : "Peter", "20"
print(somev3) # Output : ('Peter', '20')
somev3 = "Peter", "20"
创建一个 tuple
就像一个列表接受它是不可变的。
相当于:
somev3 = ("Peter", "20")
#or
somev3 = tuple(["Peter", "20"])