Xmlrpclib in Python, what is casting

Given a list, write a Python program to convert the given list to string.

There are various situation we might encounter when a list is given and we convert it to string. For example, conversion to string from the list of string or the list of integer.

Example:

Input: ['Geeks', 'for', 'Geeks'] Output: Geeks for Geeks Input: ['I', 'want', 4, 'apples', 'and', 18, 'bananas'] Output: I. want 4 apples and 18 bananas

Let's see various ways we can convert the list to string.

Method # 1:
Iterate through the list and keep adding the element for every index in some empty string.



 
 

Method # 2: Using .join () method

 
 
 

But what if the list contains both string and integer as its element. In those cases, above code won't work. We need to convert it to string while adding to string.

Method # 3: Using list comprehension

Output: I want 4 apples and 18 bananas

Method # 4: Using map ()
Use map () method for mapping str (for converting elements in list to string) with given iterator, the list.

Output: I want 4 apples and 18 bananas

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your data structures concepts with the Python DS Course. And to begin with your machine learning journey, join the Machine Learning - Basic Level Course

My Personal Notesarrow_drop_up