0 points
Submitted by a_sharma10
over 8 years

I don't understand Dot Notation

I don’t understand it at all! Will someone talk me through it please?

Answer 517049b3ec2a693b78001d30

26 votes


Sure (note that the following applies specifically to Python but is also true of many other languages). Python, like many programming languages, supports Object Oriented Programming or OOP for short. In this paradigm (type of programming), we approach ideas as Objects much as we do in the real world. Each Object is an instance of a Class or a type of object. For example, I am Michael Rochlin. I am a person. I am also a Codecademy member and also a Codecademy Moderator. So we could say that there is an object, which we will call michael_rochlin and it is an instance of a class person.

Now every person can say his/her name so we might have a function or method that tells the person to say his/her name. That method would be called say_name. It would be written inside the definition of the class person so that every person could use it.

Then we would create an instance of person and name it michael_rochlin. This instance is only one person and we could have other instances like zach or eric or linda(who are all Codecademy staff members BTW.)

So what does all this have to do with dot notation? Dot notation allows us to tell a instance of a class to use one of the methods inside that class. So if we called michael_rochlin.say_name() it would call the method say_name() that was written in the person class because michael_rochlin is a person.

“But Michael, we haven’t learned anything about classes or OOP or objects or anything like that. What are you talking about!??”

In Python, almost everything you use is an object. You have used at least seven different classes of Objects. You have used Integers, Floats, Strings, Lists, Tuples, Dictionaries and Booleans. (don’t worry if you haven’t, you will) These are all special classes in Python and each has it’s own methods.

One method of the List class is append() which appends a value to a list. What you are really doing is calling the method append from the List class on that object.

(There is a similar idea by modules, but its practically the same…)

Hope that helped, even if it was a little complicated. If you want more help, let me know

Submitted by Michael Rochlin
over 8 years


a_sharma10 over 8 years

woahhh… I didn’t understand that. But thanks for your time and effort! Really appreciated!

Michael Rochlin over 8 years

Ya like I said. I’ll write a much simpler version right now also…

corner xu over 8 years

I like this version. This question has confused me for a long time. Thx for this excenllent answer. May I ask another question? Is there any rules about the code used in the brackets of a dot function?Like what how can I use “y” in x.upper(y)?

Simon Bhattacharya over 8 years

@corner xu hmm, you cannot pass an argument in upper() function, say for an example if you try to run this code

x = “this is in small caps” y = “hmmm”

now if you ttry to print x.upper(y) you will get a error saying as

TypeError: upper() takes no arguments (1 given) if that’s what you meant. @michael thanks for the brief answer, quite a bit helpful in understanding OOP

Santosh Jayanthy over 7 years

i like Michael’s explanation…awesome…codecademy is gonna change my life…thanks

Timo J over 7 years

This was beautiful <3

spinc over 6 years

That is the first time I have been able to see the relationship the different ‘parts’ , thank you, really helpful analogy.

skinners82 over 6 years

This was a really helpful explanation. Thanks!

Answer 5175b72484050ddd5a0000cb

9 votes


So here’s a simpler explanation. There are two kinds of functions (actually one is technically a method but we’ll ignore that). One kind of function takes an argument by putting that argument inside the parentheses. For example - len("mystring") will return 8 because there are 8 letters in "mystring". (See footnote one for slightly more detail)

Another kind of function is one that is specific to a type or class of objects. An example of a class is List. An example of a List is [1,2,3,4]. The class List has functions defined that work specifically on Lists. To use those functions on a specific List we would use dot notation. For example, to use the special function append on a List called my_list we would write my_list.append(insert_thing_to_append). (See footnote 2 for a little more)

Hope that is a simpler way of explaining it. You will come across dot notation by functions for Lists, Dictionaries and Strings quite often. You will also use them for user-defined classes and even for using specific functions from modules and libraries.


  1. len is an example of a function that is defined in the __builtin__ namespace which is the environment you are working in. Almost everything in Python is actually an object and therefore part of a class or a module. So technically len and other such built-in global functions are part of the __builtin__ module. Not important to know though…
  2. There are many kinds of built-in classes, the most common being List, String and Dict. Each of these builtin classes have associated methods that are defined in the source code.
  3. In general, dot notation tells Python to look inside the space that is before the dot for code to execute. You can use dot notation to access the specific version of a certain function that is defined in a different class or a different module. For example, if I have one module that is called basicmath and another called advancedmath and they both have constants PI, but with different values, then I would call basicmath.PI to get that version of PI, and advancedmath.PI to get its version of PI.
Submitted by Michael Rochlin
over 8 years


Test_man about 8 years

This is helpful (especially along with the answer from Michael), but what is the best way to get to know when to use either? Or is it rote memorization?

Timo J over 7 years

Can this be included in the lesson? As in this explanation.

jeremyisboss almost 7 years


mousewithatache over 6 years

Lesson #9 says “Methods that use dot notation only work with strings.” But you say list can use dot notation too?