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 trialChristina De Longhi
3,641 PointsHow does one accommodate for last names with a space in them?
How does one accommodate for last names with a space in them in a scenario like this? For example, the last name "De Longhi"? Thanks!
4 Answers
Steven Parker
231,236 PointsThe "split" method takes an optional keyword argument to limit how many splits are performed:
first, last = input("Enter your full name: \n").split(' ', maxsplit=1)
Christina De Longhi
3,641 PointsThanks!
Steven Parker
231,236 PointsGlad I could help, and happy holidays!
Leslie Lewis
1,088 PointsAnd if the name was something like "Anne Marie Lewis?"
Steven Parker
231,236 PointsYou might need to ask the user to enter the name a certain way and program for that (like last name first with a comma). Otherwise, how could you tell if it's the first or last that has 2 words?
Leslie Lewis
1,088 PointsMy sister-in-law would not like that. This is why separate boxes for first and last names works best. But "split" is a neat trick - just not for this
Steven Parker
231,236 PointsSeparate boxes is another way to place responsibility for making the distinction on the user.
Leslie Lewis
1,088 PointsThere are many times when the user would prefer to take responsibility for designating their family and given names. Take some of my friends: Chang Woo Hee, Horvat Andras, Anna Lopez Gonzales, - or even myself when I use all four names in my official legal name.
Steven Parker
231,236 PointsThat is a good example of a UX design decision. But then that's a separate course series.
Victor Warner
2,869 PointsVictor Warner
2,869 PointsHow come at maxsplit = 3 I get an error for too many values to unpack ( expected 2)
Enter full name: Keanu Rea ves