Functions that use brackets || dot notation


#1

In the strings and console section 9 (Dot Notation) it is said that len() is not exclusive to strings and can be used for other data types so I tried this:

pi = 3.14
print len(pi)

and it does not work. Clrearly it does not work for the integer data type.

Then again I tried

pi = 3.14
if = str(pi)
print len(if)

and still it won't work. So can anybody please tell me why is this so? And what is the difference between functions that use dot notation and brackets? Also, with so many functions out there how do I know if it requires the dot notation or the bracket use?

Thanks!


#2

if is a reserved keyword, you can't use it for variable name

len() also works for list.

Of function you use often, you will remember them (so if its sorted([3,2,1] or [3,2,1].sort())

once you learned about functions and classes/objects, it will also make a bit more sense (this will be later in the course)

If you don't know, you can always check documentation.


#3

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