In the below operation, we are using a as an object as well as an argument.
a = "Hello, World!"
print(a.lower()) -> a as an object
print(len(a)) -> a as a parameter
May I know how exactly each operations differs in the way they are accessing a?
In the below operation, we are using a as an object as well as an argument.
a = "Hello, World!"
print(a.lower()) -> a as an object
print(len(a)) -> a as a parameter
May I know how exactly each operations differs in the way they are accessing a?
Everything in python (everything that can go on the rhs of an assignment) is an object, so what you can pass as an argument to a function IS an object, always. Actually, those are totally orthogonal concepts: you don't "use" something "as an object" - it IS an object - but you can indeed "use it" (pass it) as an argument to a function / method / whatever callable.
May I know how exactly each operations differs in the way they are accessing a?
Not by much actually (except for the fact they do different things with a
)...
a.lower()
is only syntactic sugar for str.lower(a)
(obj.method()
is syntactic sugar for type(obj).method(obj)
, so in both cases you are "using a
as an argument".