Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialReed Williams
3,323 PointsPython Basics > shopping list > lists and strings > question 2 of 3 > syntax
Directions:
Create a variable named greeting_list that's the string "Hi, I'm X" split on the spaces.
Current syntax:
full_name = "Craig Reed Williams" name_list = full_name.split() greeting_list = split("Hi, I'm ") + name_list
What is the correct syntax?
Thank you.
full_name = "Craig Reed Williams"
name_list = full_name.split()
greeting_list = split("Hi, I'm ") + name_list
1 Answer
Kenneth Love
Treehouse Guest TeacherTo split a string on the spaces, you call the .split()
method on the string.
>>> "Hi, I'm a string".split()
["Hi", "I'm", "a", "string"]
You don't need to combine name_list
and greeting_list
.