+ 1

Why we use concatenation in python?

Why add two strings together instead of just type two words.

6th May 2021, 11:42 PM
Balavan Chauhan
Balavan Chauhan - avatar
3 Answers
+ 7
string concatination is usefull when you do not know the value of the strings you add together s = "5 + 6 = " + "11" wouldn't be very usefull here. However, in most code, you won't know most variable. Here is an example: x = int(input()) y = int(input()) result = x + y s = str(x) + " + " + str(y) + " = " + str(result) print(s) Using string concatination, I was able to print out the complete math used without knowing any actual values. And little shortcut for those concatinations using f strings: s = f"{x} + {y} = {result}" I hope this helps!
7th May 2021, 12:04 AM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Every thing has its uses . as long as you are familiar with advanced problem in python you will find their application.
7th May 2021, 4:56 AM
Yash Wable 🇼🇳
Yash Wable 🇼🇳 - avatar
+ 1
changeless = " joined to chat" changing = ["John", "Jane", " Brad", "David", "Jose"] for name in changing: print(name+changeless) #outputs: #John joined to chat #Jane joined to chat #.... #Jose joined to chat.
7th May 2021, 5:54 AM
Shadoff
Shadoff - avatar