+ 4

How Python adds two strings without using +operator?

For eg. >>>"Hello" "world" If you do this. Then output will be "Hello world"

1st Oct 2019, 12:44 PM
Gaurav bhojwani
Gaurav bhojwani - avatar
13 odpowiedzi
+ 2
From the link I sent since you probably didn't bother to read it: "Multiple adjacent string literals (delimited by whitespace), possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation. Thus, "hello" 'world' is equivalent to "helloworld". This feature can be used to reduce the number of backslashes needed, to split long strings conveniently across long lines, or even to add comments to parts of strings, for example: re.compile("[A-Za-z_]" # letter or underscore "[A-Za-z0-9_]*" # letter, digit or underscore ) Note that this feature is defined at the syntactical level, but implemented at compile time. The ‘+’ operator must be used to concatenate string expressions at run time. Also note that literal concatenation can use different quoting styles for each component (even mixing raw strings and triple quoted strings)."
6th Oct 2019, 12:40 PM
jtrh
jtrh - avatar
+ 7
s = [ "Happy", "SoloLearning", ";)" ] separator = " " x = separator.join(s) print(x) # x = "Happy SoloLearning ;)"
6th Oct 2019, 1:17 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 3
https://docs.python.org/2/reference/lexical_analysis.html#string-literal-concatenation
1st Oct 2019, 12:48 PM
jtrh
jtrh - avatar
+ 3
There's a string method: "".join(["Tom", "ate", "toe"]) -> "Tomatetoe"
1st Oct 2019, 1:39 PM
Seb TheS
Seb TheS - avatar
+ 3
It seems to come from the Python standard Gaurav bhojwani as jtrh mentioned.
6th Oct 2019, 1:38 PM
Sonic
Sonic - avatar
+ 2
I think I have answered all the possible ways of doing it .
3rd Oct 2019, 6:49 AM
namrata garg
namrata garg - avatar
+ 2
I still have doubt that without + operator how these strings get concatenate 🤔 namrata garg Sonic
6th Oct 2019, 12:29 PM
Gaurav bhojwani
Gaurav bhojwani - avatar
+ 2
Perhaps in Python, adjacent strings get concatenated.
6th Oct 2019, 12:31 PM
Sonic
Sonic - avatar
+ 2
This is what the question is.. "how"😂. This means we don't require + in python
6th Oct 2019, 12:38 PM
Gaurav bhojwani
Gaurav bhojwani - avatar
+ 1
Faisal Reza [Indian] there is no + operator
2nd Oct 2019, 5:09 AM
Gaurav bhojwani
Gaurav bhojwani - avatar
+ 1
If you want to print "HELLO" " WORLD" You can simply use - print("HELLO WORLD") or if you want to print "I" "live" "in" "Delhi" then simply write all the words in between " " like print (" I live in Delhi") BUT if you have printed hello already and now you want to add world or your name with it ,then you can concatenate the strings i.e. join them by M1- Print("hello"+"world") or M2- str1=" hello" str2= "world" print(str1+str2)
3rd Oct 2019, 6:35 AM
namrata garg
namrata garg - avatar
+ 1
namrata garg I believe they are commenting about the ability to concatenate without using +.
3rd Oct 2019, 6:42 AM
Sonic
Sonic - avatar
0
Use only "" with another one
2nd Oct 2019, 6:06 PM
Pushpendra Singh
Pushpendra Singh - avatar