A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

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

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

0

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

All Answers

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

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

elephant:sparrow:eagle:tiger

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.

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now