How to Remove the Space Between a Variable and a String in Python?

Estimated read time 1 min read

If you want to remove the space between a variable and a string in Python, you can use string concatenation. Here’s an example:

name = "John"
greeting = "Hello,"

# Concatenate the variables without a space
message = greeting + name

print(message) # Output: "Hello,John"

In this example, we have a variable name with the value "John", and a string variable greeting with the value "Hello,". To remove the space between the variables when they are concatenated, we simply remove the space between them in the concatenation statement. The resulting message will be "Hello,John".

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply