+ 2
Why we can not subtract strings even if we can add?
Eg: print ('3' +'3') gives 33 print ('3' - '3') gives error
7 ответов
+ 4
What do you expect from subtracting string? In your case do you expect an empty string? What about "334"-"3", "abc"-"&", "1244"-"4421"?
Well, if there is a rule of subtracting string, it would hardly make sense. To remove a part of the string, you can use slice.
+ 4
The class string did not implement it.
https://code.sololearn.com/cJLVkXZN1Vlw/?ref=app
+ 3
String subtraction makes no sense, but if you want results like these:
"ABC" - "BC" = "A"
"ABC" - "AB" = "C"
then you can use str.replace method:
"ABC".replace("BC", "") = "A"
"ABC".replace("AB", "") = "B"
str1.replace(str2, str3) gives a copy of string str1, where all occurences of substrings str2 will be replaced with substrings str3.
+ 1
Because "+" is not only a mathematical operator for summing numbers, but also a concatenation operator that concatenates strings.
+ 1
LoL!
+ operator on string doesn't add them
It concatenate two strings.
And - sign gives error because programmer of PYTHON didn't add that in syntax
0
That's not addition, it is concatenation...
- 2
Print(name_input())