What's the difference between str and 'hello' ?

H

hong Yu

I am new to python.
I was confused:
['h', 'e', 'l', 'l', 'o']

I want to combine the items in the list into a string.
So:
'hello'

but:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: descriptor 'join' requires a 'str' object but received a 'list'

So why TypeError raised?
and
What's the difference between str and 'hello' ?

Thanks a lot.
 
P

paulC

hong said:
I am new to python.
I was confused:
['h', 'e', 'l', 'l', 'o']

I want to combine the items in the list into a string.
So:
'hello'

but:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: descriptor 'join' requires a 'str' object but received a 'list'

So why TypeError raised?
and
What's the difference between str and 'hello' ?

Thanks a lot.


str is a class, 'hello' is instance of the class; the method join
expects to receive an instance as its first parameter so:-
'hello'

Regards, Paul
 
H

Heiko Wundram

Am Donnerstag, 19. Mai 2005 11:27 schrieb hong Yu:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: descriptor 'join' requires a 'str' object but received a 'list'

What's the difference between str and 'hello' ?

str.join("",a) <=> "".join(a)
(<=> as in equivalence relation)

HTH!

--
--- Heiko.
listening to: Bjork Guðmundsdottir & Trio - Luktar-Gvendur
see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQBCjH8Mf0bpgh6uVAMRAklxAJ0agCh+uMfLKJ3Ug7EpWZTInUCthgCfXYZs
3WEE5A5+V6amglBC7wSeHyY=
=HbQR
-----END PGP SIGNATURE-----
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top