1

I'm new to python.I read that every identifier is an object reference in python (including primitive data types). We use object reference to call object methods. For example

a="hello world"

Here a is a reference to string object and i use this reference to call string object methods.But what I found today is that I can directly use the object itself instead of a reference. i.e both a.upper() and "hello world".upper() are valid.What i need to know the underlying logic of calling an object method in python.How am I able to use both object reference and object itself to call methods. Is there a difference in above two methods??

3
  • 3
    docs.python.org/reference/datamodel.html, docs.python.org/reference/executionmodel.html Commented Aug 29, 2012 at 12:16
  • 3
    Welcome to Stack Overflow. Your question suggests that you are very new to object-oriented programming. I would suggest that you go through the Python tutorial at docs.python.org/tutorial/ which will answer this question alongside many others. Commented Aug 29, 2012 at 12:35
  • @HerrKaputt yeah,i'm a noob...Thnx,i'll look into that Commented Aug 29, 2012 at 12:46

1 Answer 1

1

Reference variables are just names for objects. "hello world" is just an unnamed object - an object doesn't need a name to call methods on it, it just needs to exist.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.