When to Use Parentheses with Dot Notation?


#1

When should we use and when should we not use parentheses with dot notation?


FAQ: Learn Python -Date and Time- Extracting Information
#2

to access class and instance variable, do not use parentheses.

to use methods, use parentheses. Example:

class Example(object):
    shared = "hello world" # class variable
    def __init__(self, name):
       self.name = name # instance variable
   
    def method_example(self): # method
      return "hello %s" % self.name

e = Example("daniel")
# accessing class variable
print e.shared
# accessing instance variable
print e.name
# accessing method
print e.method_example()

now imaging strings and lists and so on are classes (you will get more about classes later), so when you create a string:

"hello there"

you create a instance of string class. The class has several methods and variable. .upper() for example is a method

I know this is confusing right now, but this will make more sense once you learned about classes