Python Container Types
Container Types in python
- Ordered sequences, fast index acess , repeatable values
code
#ordered sequences, fast index access, repeatable values list [1, 5, 9] ["x", 11, 8.9] ["mot"] tuple (1, 5, 9) 11, "y", 7.4 ("mot",) str bytes (ordered sequences of chars/bytes) #Key container, no a priori order , fast key access, each key is unique #dictionary dict {"key":"value"} dict (a=3, b=4, k="v") #(key/value associations) {1:"one", 3:"three", 2:"two", 3.14:"n"} #collection set{"key1","key2"} {1, 9, 3, 0} #keys=hashable values (base types, immutables...) frozenset immutable set
Example
a=[1,5,9] b=["x",11,8.9] c=["mot"] d=(1,5,9) e=11,"y",7.4 f=("mot",) g={"key":"value"} j={"key1","key2"} k={1,9,3,0} print a print b print c print d print e print f print g print j print k
No comments:
Post a Comment