Python String Exercise

Write a program in Python to use the string join operation to create a string that contains a colon as a separator.

Solution

In Python append() method is used to add an item to the end of the list. It adds a single item to the existing list. On every append function call the length of the list increases by one.


Syntax of append() method
list.append(item)

Here, item is the required parameter, it is of any data type. This method returns the updated existing list.

This is following solution to create a string that contains a colon as a separator.

content = []
content.append('elephant')
content.append('sparrow')
content.append('eagle')
content.append('tiger')
str = ':'.join(content)
print str

Output of the above code
Python Append String

In the above code, we have taken a blank content list and appends the four elements by using append method. We have used join() method to add a colon as a separator.





Related Articles

Python program for Prime Number
Odd Even Program in Python
Python program to convert Celsius to Fahrenheit
Python Convert XML to CSV
Python Text to Speech
Python send mail to multiple recipients using SMTP server
How to generate QR Code in Python using PyQRCode
Python programs to check Palindrome strings and numbers
CRUD operations in Python using MYSQL Connector
Fibonacci Series Program in Python
Python File Handler - Create, Read, Write, Access, Lock File
Python convert XML to JSON
Python convert xml to dict
Python convert dict to xml




Read more articles


General Knowledge



Learn Popular Language