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 trial

Python

Jeffery Jones
Jeffery Jones
2,769 Points

Why is the space needed in the parens after split?

why couldn't it just be:

first, last = input('Enter your full name: \n').split()

instead of:

first, last = input('Enter your full name: \n').split(' ')

I get the same result either way? Just curious

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Jeffery Jones! Just following up on what Jonathan Grieve and Brandon White have posted. Both are valid. But they do slightly different things, though, for your purposes, it will achieve the same results.

The .split() with no arguments splits on all white space. That includes spaces, tabs, and newline characters.

However, the .split(' ') splits explicitly on a space. It won't split on tabs and newline characters.

Hope this helps! :sparkles:

Jeffery Jones
Jeffery Jones
2,769 Points

very helpful, thank you both so much!

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

It's what's called a separation parameter. Something that provides separation in your list. It could be a comma, or a dash or an empty string as you're doing.

For eample

apples, oranges, pears

Brandon White
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 Points

Following up on what Jonathan has said, "It's better to be explicit, than implicit". With the second way, it's very obvious what delimiter is being used to split up the user's response.