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. ie 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??
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.