what is the difference between the two kinds of brackets?

narutocanada at gmail.com narutocanada at gmail.com
Sat Oct 20 12:15:15 CEST 2007


hi

what is the difference between the two kinds of brackets?
I tried a few examples but I can't make out any real difference:
lst = [10, 20, 30]
print lst[0]
print lst[2]
print lst
lst = (10, 20, 30)
print lst[0]
print lst[2]
print lst

lst = [10, 20, 40, "string", 302.234]
print lst[0:2]
print lst[:3]
print lst[3:]
lst = (10, 20, 40, "string", 302.234)
print lst[0:2]
print lst[:3]
print lst[3:]

10
30
[10, 20, 30]
10
30
(10, 20, 30)
[10, 20]
[10, 20, 40]
['string', 302.23399999999998]
(10, 20)
(10, 20, 40)
('string', 302.23399999999998)

Are these two kinds of brackets mean the same thing in the "list"
context? Thanks.




More information about the Python-list mailing list