This forum is now read-only. Please use our new forums at

Strings & Console Output Forum

View Course

219 points
Submitted by
over 2 years ago

I don't understand Dot Notation

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

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

1693 points
Submitted by
Michael Rochlin
over 2 years ago


2b95b8a7dc0ca2591b6ee364a14ecf2a?s=140&d=retro a_sharma10 over 2 years ago

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

4f84976a93d918000300de59_981251210 Michael Rochlin over 2 years ago

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

4d07759a20339a5db39a0e1fec6dae5c?s=140&d=retro corner xu over 2 years ago

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)?

90787dbba7c83be5ca09b8e2e24f488a?s=140&d=retro Simon Bhattacharya over 2 years ago

@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

02b320fa91518d65dc63d46b130e40f8?s=140&d=retro santoshnnag over 1 year ago

i like Michael's explanation...awesome...codecademy is gonna change my life...thanks

2a44da1445e5ed4259c1cd80f4d0e784?s=140&d=retro Timo J over 1 year ago

This was beautiful <3

16929dbce4df381a98b3ea501070bc92?s=140&d=retro spinc 5 months ago

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

Bf7443c29b94a10bc89907cdef95877a?s=140&d=retro skinners82 4 months ago

This was a really helpful explanation. Thanks!

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.

1693 points
Submitted by
Michael Rochlin
over 2 years ago


522cfe06548c35874f008b14_551949238 Test_man about 2 years ago

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?

2a44da1445e5ed4259c1cd80f4d0e784?s=140&d=retro Timo J over 1 year ago

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

Cfbdc938b7feb275d0c2b645a74b7c31?s=140&d=retro jeremyisboss 9 months ago


89d1ea02eec4e5407b64e13a67e9dfe5?s=140&d=retro mousewithatache 5 months ago

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