[Tutor] Concatenating Strings

Dave Angel d at davea.name
Tue May 29 04:07:45 CEST 2012


On 05/28/2012 10:00 PM, Jeremy Duenas wrote:
> I am trying to understand the point behind using the  '+' character when
> trying to concatenate strings. I am new to learning Python and going through
> the book "Python Programming for Absolute Beginners 3rd ed."  and do not
> understand the point or reason for concatenating strings. The reason I do
> not understand is when experimenting to understand what was being taught I
> wrote:
>
>
> print("\nThis string" "may not" "seem terr" "ibly impressive")
>
>  
> then wrote:
>
>  
>
> print("\nThis string" + "may not" + "seem terr" + "ibly impressive")
>
>  
>
>
> and they both printed the same output..so why would I want to use  '+' to add
> strings if there seems to be no reason too?
>
>  
>

As long as they're all literal strings, you can use the implicit
concatenation.  Or you can just make one longer string.  Makes no
difference, other than white space and sometimes prettiness.

However, as soon as one of the strings is a variable of type "str" then
you need the "plus sign."



-- 

DaveA



More information about the Tutor mailing list