Python Tutorial : Putting two strings together


Now we are going to see a simple example that will show you who to
concatenate two or more different strings. For instances, imagine I
would like to combine the names and last names of the presidential
candidates of the United States (Barack Obama, John McCain). The name
and last name are two separated strings. Let’s see how we can do that
in Python.

1. I must have to write in the Python Shell:

>>> “Barack”

2. And then Press ENTER.

3.The you have to write:

<strong>>>> “Obama”


4. And then Press ENTER. Once you press the Enter Key you will see
the string displayed on screen. Now if you like link these two
separated strings you should following the step 5.
5. Write this:

>>> “Barack” + “Obama”


6. Press enter and will be displayed the unified string
“BarackObama”. If you want separate the name from the last name
with a space. You should create an empty string between the last
name and last name. I will show you how do it.

>>> “Barack” + “” + “Obama”


7. Once you press the Enter Key you will notice that the name and
last name is correctly written and separated by a space. You can
do the same using the name and last name of the candidate John
McCain. The following box shows an example of this.

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.