Home >Backend Development >Python Tutorial >How to merge two columns of strings in python?
#How to merge two columns of strings in python?
How to merge two columns of strings in python:
1. In many cases, we need to merge strings. For example: you need to store the last name and first name in different variables, and then combine them into one when displaying
first_name = 'oliver' last_name = 'smith' full_name = first_name + ' ' + last_name print(full_name)
Print result:
oliver smith
2. Use the ( ) sign in python to merge strings
This method of string merging is called splicing, and the information stored in variables can be used to create complete information
first_name = 'oliver' last_name = 'smith' full_name = first_name + ' ' + last_name print('Hello ' + full_name.title() + '!')
Print result:
Hello Oliver Smith!
The title() method here capitalizes the first letter of the word to make the name display more formatted
3. You can also create a variable to store the entire statement
first_name = 'oliver' last_name = 'smith' full_name = first_name + ' ' + last_name msg = 'Hello ' + full_name +'!'print(msg)
In this way, what is displayed in the print statement is not that complicated!
Recommended tutorial: "python video tutorial"
The above is the detailed content of How to merge two columns of strings in python?. For more information, please follow other related articles on the PHP Chinese website!