[Tutor] Concatenation

Joel Goldstick joel.goldstick at gmail.com
Fri Aug 19 13:59:14 EDT 2022


On Fri, Aug 19, 2022 at 1:46 PM Gibson Green via Tutor <tutor at python.org> wrote:
>
> How can I concatenation a string statement with an integer? For example: Congratulations, you are now 24 years old. Age variables was declared and converted to an integer.
> I have:
>   print ( ‘ Congratulations, you are now’ + age+ ‘ years old’)
>
> Had an error about concatenation between integer and strings . Please  help. Thanks.
>
> Gibson.
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

There are lots of ways.  The most recent addition to python are
f-strings.  This works:

>>> age = 5
>>> print (f"my age isn't {age}")
my age isn't 5



-- 
Joel Goldstick


More information about the Tutor mailing list