0

In the below operation, we are using a as an object as well as an argument.

a = "Hello, World!"

  1. print(a.lower()) -> a as an object

  2. print(len(a)) -> a as a parameter

May I know how exactly each operations differs in the way they are accessing a?

isherwood
  • 58,414
  • 16
  • 114
  • 157
Gt_R
  • 225
  • 1
  • 3
  • 10

1 Answers1

1

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".

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118