Python for Everybody - Working with Lists

Tell us what’s happening:

Hi everyone,
the instructor of the Python For Everybody course has shown several lists up until this point, one example is the list
friends = [ ‘Joseph’, ‘Glenn’, ‘Sally’ ]
I’m wondering if it’s necessary to have the blanks at the beginning and the end, as he has sometimes left them out. Does this have any meaning?
Thanks for your time!

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge Information:

Python for Everybody - Working with Lists

Do you mean spaces inside of the [ ] before first and after last elements? It’s not necessary, sometimes it might help with making things easier to read.

1 Like

Yes, I was wondering what the rules and/or common practice here is. Thanks for your helpful reply!

Can check PEP 8 for things like this: https://pep8.org/. Here are some eamples:

my_list = [
    1, 2, 3,
    4, 5, 6,
    ]

__all__ = ['a', 'b', 'c']

Although this rule isn’t stated explicitly, the second example there seems to recommend no space between the bracket and quote. (Unless you are breaking it up into multi-line.)

Personally, I don’t mind that extra space. I might go with having each name on a separate line.

1 Like

thanks a lot for the info!

1 Like