I have two strings: Show
How can I get
msw 41.8k9 gold badges83 silver badges108 bronze badges asked Jul 13, 2012 at 12:58
Simply just add a space between the two strings:
this will give you
You can use a function such as Based on: "Simple is better than complex." (The Zen of Python "import this") answered Jul 13, 2012 at 12:59
LevonLevon 132k33 gold badges197 silver badges186 bronze badges 3 You can use join to concatenate your strings together with your selected delimiter.
answered Jul 13, 2012 at 13:00
Christian WittsChristian Witts 11k1 gold badge31 silver badges44 bronze badges Since Python 3.6, you can use f-strings to join two strings with ease. The code is more succinct and the variables are referenced directly within the context of the string.
The above code would output the following:
The answered Mar 1, 2019 at 16:33
noddynoddy 2,9373 gold badges24 silver badges20 bronze badges Python supports the string formatting operations and a template system (the latter is technically a simple but powerful class) as part of the string module. While the plus operator does its work, the lack of string formatting can influence a lot the readability of the code. A basic example for string formatting:
georg 206k48 gold badges292 silver badges373 bronze badges answered Jul 13, 2012 at 13:28
VidulVidul 9,7162 gold badges17 silver badges20 bronze badges 2 Not the answer you're looking for? Browse other questions tagged python or ask your own question.When I run this code it behaves like expected:
I get this:
The problem is that when I try to do some modification:
to print what I need in the same line i get it like spaces from Q2 disappeared somewhere and didn't concatenate.
Anyone could help me with this? I have tried in many ways and can't get it.
jww 92.6k85 gold badges380 silver badges833 bronze badges asked Jul 31, 2017 at 11:37
1 In modification you omitted the for loop. In your initial code there are two for loops and in your modification you omitted the second for loop. answered Jul 31, 2017 at 11:46
RahulRahul 10.2k4 gold badges49 silver badges86 bronze badges 1 As the
answered Jul 31, 2017 at 11:56
Serge BallestaSerge Ballesta 138k11 gold badges114 silver badges234 bronze badges 1 If this is your expected output,
Modify #Q2 to :
answered Jul 31, 2017 at 11:52
SajinSajin 1,5981 gold badge13 silver badges18 bronze badges 0 Not the answer you're looking for? Browse other questions tagged python concatenation spaces or ask your own question.How do I concatenate a string with a space?There are two ways to do this:. Add double quotation marks with a space between them " ". For example: =CONCATENATE("Hello", " ", "World!").. Add a space after the Text argument. For example: =CONCATENATE("Hello ", "World!"). The string "Hello " has an extra space added.. How do you concatenate special characters in Python?String Concatenation is the technique of combining two strings. String Concatenation can be done using many ways.. Using + operator.. Using join() method.. Using % operator.. Using format() function.. Using , (comma). How do you concatenate a string with a comma in Python?Call the join() method from 'String to insert' and pass [List of strings] . If you use an empty string '' , [List of strings] is simply concatenated, and if you use a comma , , it makes a comma-delimited string. If a newline character \n is used, a newline will be inserted for each string.
How do you concatenate two strings without space in Python?Method 2: Remove spaces from a string using split() and join() First, we use the split() function to return a list of the words in the string, using sep as the delimiter Python string. Then, we use join() to concatenate the iterable.
|