It is fun.the result of str.lower(str())

  • Thread starter Sullivan WxPyQtKinter
  • Start date
F

Fredrik Lundh

Sullivan WxPyQtKinter said:
Guess what would be the result of these functions:
str.lower('ASFA')
str.join(str(),['1','1','1'])
str.join('a','b')

If you guess them correctly, please explain.

as I just said, I.method() and C.method(I) are equivalent,
so that's just an odd way to write

'ASFA'.lower()
str().join(['1', '1', '1'])
'a'.join('b')

which, given that str() returns an empty string, and a string
behaves like a sequence of individual characters, is equivalent
to

'ASFA'.lower() => 'asfa'
''.join(['1', '1', '1']) => '111'
'a'.join(['b']) => 'b'

</F>
 
B

bruno at modulix

Sullivan said:
Guess what would be the result of these functions:

s/functions/method calls/

=> 'ASFA'.lower() => 'asfa'

=> ''.join(['1','1','1']) => '111'

=> 'a'.join('b') => 'b'
If you guess them correctly,

No need to guess, there's this thing named the python interactive shell,
you know... And it even has an integrated help system.
please explain.

Explain what ? It's all in the fine manual.

* Klass() is a call to Klass's constructor and returns an instance of Klass.

* Klass.method(klass_instance) is the same as klass_instance.method()
* str is the builtin string class.
* without any args, the str constructor returns an empty string
* str.join() takes a sequence of strings and join'em with the target str
instance as separator

Now would you be kind enough to explain what's funny about all this ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top