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 Python Basics (2015) Python Data Types Splitting and Joining

harpreet grewal
harpreet grewal
19,018 Points

.join in python to create a period after every instance

how do i create a period after each instance of an array

example: flavors = ["chocolate", mint", "strawberry"] ". ".join(flavors) creates 'chocolate. mint. strawberry"

but what if i want a period after the strawberry as well?

2 Answers

You can "add" (concatenate) the period character to the end of the string.

For example:

"Harpreet is learning Python" + "!"  # This code returns "Harpreet is learning Python!"

So, if you want to "add" a period/dot/full stop to the end of your string, you can do this:

 flavors = ["chocolate", "mint", "strawberry"]

". ".join(flavors) + "."  # I think this does what you want :)

I hope this helps. ~Alex