24: Append One String to Another in Python Program


You can make use of the + operator in Python to concatenate one string with another.


Program 1:
# Python Program to concatenate two strings

one_string = "hello ";
another_string = "world!"

concatinated_string = one_string + another_string

print(concatinated_string)
Output:

hello world!


This may be a possible solution if you have a few strings to concatenate, what if you have a long list of string values to concatenate, in such scenarios you can make use of a join() method from the string class.


Program 2:
countries = ["USA", "Canada", "Mexico", "Germany", "Australia"]
countries_str = ', '.join(countries)

print(countries_str)
Output:

USA, Canada, Mexico, Germany, Australia

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap