Home > Backend Development > Python Tutorial > How to merge two columns of strings in python?

How to merge two columns of strings in python?

coldplay.xixi
Release: 2020-06-29 17:07:00
Original
5200 people have browsed it

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)
Copy after login

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() + '!')
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template