Dot Notation Data Types

#1

What other types of data can len() and str() work with?

#2

Anything that is an iterable will have a length property. Strings, lists, dictionaries and tuples all fall into this group.

``````    a = (1,2,3,4,5,6,7,8,9)
print (len(a))                         # 9

b = [1,2,3,4,5,6,7,8,9]
print (len(b))                         # 9

c = {'a':1,'b':2,'c':3}
print (len(c))                         # 3

d = "string, list, tuple, dictionary"
print (len(d)                          # 31``````

Jsut about anything can be converted to a string owing that everything is a text object at its core.

``````print (str(a))           # (1, 2, 3, 4, 5, 6, 7, 8, 9)

print (str(b))           # [1, 2, 3, 4, 5, 6, 7, 8, 9]

print (str(c))           # {'b': 2, 'a': 1, 'c': 3}

f = lambda x: print (x)
print (str(f))           # <function <lambda> at 0x02EF68A0>``````

The last one is not really a conversion. This will need to be followed up.

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.