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 is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

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