Q:

Python | Appending text at the end of the string using += Operator

belongs to collection: Python String Programs

0

Given a string, and we have to append more string (text) at the end of the string using += operator in Python.

There are two methods to add string (text) at the end of the string:

  1. String.append() Method
  2. By using += operator

    Example:

    Input:
    str: 'New Delhi'
    
    Concatenation of more text 
    str += ' ' #space
    str += 'Chennai'
    
    str += ' ' #space 
    str += 'Mumbai'
    
    str += ' ' #space 
    str += 'Bangalore'
    
    Output:
    str: 'New Delhi Chennai Mumbai Bangalore'

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

# Python program to add strings 
# to the string 

str = 'New Delhi'
str += ' '    #adding space 
str += 'Chennai'
str += ' '    #adding space
str += 'Mumbai'
str += ' '    #adding space 
str += 'Banglore'

# print the string 
print 'str:',str

Output

str: New Delhi Chennai Mumbai Banglore

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Concatenate two strings and assign in ano... >>
<< Python | Create multiple copies of a string by usi...