Skip to content

Python Journey

My Coding Blog

Menu
  • Links
Menu

Python>>String Concatenation

Posted on August 29, 2022August 29, 2022 by coden00b

String concatenation is simply adding strings together.

Here are sample String Concatenation:

Sample1:

>> a = ‘Free’
>>> b = ‘Linux’
>>> c = ‘Tutorials’
>>> a + b + c
‘FreeLinuxTutorials’
>>> d = a + b + c
>>> print (d)
FreeLinuxTutorials
>>>

Sample2:

>>> a = ‘Welcome’
>>> b = ‘to my’
>>> c = ‘Site’
>>> s = ‘ ‘
>>> a + s + b + s + c
‘Welcome to my Site’
>>> d = a + s + b + s + c
>>> print (d)
Welcome to my Site

 

Sample3:

>> ‘Welcome’ + ‘ Guys’
‘Welcome Guys’

Sample4:

>> str = ‘Welcome’
>>> str = str + ‘ to my Site’
>>> print (str)
Welcome to my Site

Sample5:

>> print (str)
Welcome to my Site
>>> str = str[0:7] + ‘ to my World’
>>> print (str)
Welcome to my World

Sample6:

>> str = ‘Knock! ‘
>>> print (str)
Knock!
>>> str * 6
‘Knock! Knock! Knock! Knock! Knock! Knock! ‘

Sample7:

>> x = 10
>>> y = 10
>>> x + y
20
>>> x = ’10’
>>> y = ’10’
>>> x + y
‘1010’

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • The Zen of Python
  • Python>>String Interpolation and Formatting
  • Python>>String Methods
  • Python>>String Concatenation
  • Python>>Strings: Indexing and Slicing

Recent Comments

No comments to show.

Archives

  • January 2023
  • August 2022

Categories

  • Blog
  • Data Types