Python - String Concatenation
In Python, you can concatenate, or combine, two strings by using the +
operator. This allows you to join strings together to create a single, longer string.
Example
To merge the content of a
and b
into a new variable c
:
a = "Hello"
b = "World"
c = a + b
print(c) # This will print "HelloWorld"
Adding a Space
If you want to add a space between the two strings, you can include a space within the quotes:
a = "Hello"
b = "World"
c = a + " " + b
print(c) # This will print "Hello World"
String concatenation is a fundamental operation when working with text data, and it allows you to build more complex strings by combining simpler ones.
Last updated