CSCA20H3 Lecture : convertion between list and string .rtf

82 views3 pages
School
Course
Professor

Document Summary

>>> b="laura" m=["hello", "laura", "how", "are", "you"] print "a". join(m) Helloalauraahowaareayou m=["hello", "laura", "how", "are", "you", 3] print "a". join(m) Typeerror: sequence item 5: expected string, int found. Syntaxerror: invalid syntax--this is wrong, cause a int can"t join a str, or a listof int; Only string can join a list of string elements, if there"s a int in the list, (not the same type )m, then join won"t work. -this is right, and the added element is added to each element already present in b. -both "a" and b are str, so same time, hence join method is applicable here. Join give u a string while append is not that picky, it can add an int to a list of str. -the result of addition is different from that of append, cause join method add "a" after each element of the list/str, while append just add once. join doesn"t work on integers.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions