Python program to convert a list to string

Python program to convert a list to string. This program contains python function definition, for iterative statement , list initialization and printing. This program is for B Tech engineers and also for expert programmer as it is used in various time in python projects.

Program to convert a list to string

List is a sequence of data in same datatype per sequence. List are in brackets sequence . Example- [“archit”,”rahul”,”akash”,”pushkar”].
A string are a sequence of character without commas and joined to each other as words in sentence. Example- archit rahul akash pushkar.
We have to write a program that converts [“archit”,”rahul”,”akash”,”pushkar”] to archit rahul akash pushkar. list can be changed into string using this program and initialising the list.

Source code :

# List is to be converted in string
i=0  
def conList(list1):  
    str = ''  # initialize the empty string  
  
    for i in list1: #Iterate and add the list element to the str variable  
        str += i  
    return str  
#print(i)  
list = ["Hello"," fellow", " earthlings ","i am archit"] #intializing string   
print(conList(list)) # the converted string value is printed

Source code Explanation:

step 1:functiondefination of list is to be converted in string
i=0
def conList(list1):
step 2: initialize the empty string
str = ”
step 3:Iterate and add the list element to the str variable
for i in list1:
str += i
return str # returning to the function conlist
step 4:the converted value is printed
print(i)
list = [“Hello”,” My”, ” Name is “,”Devansh”] #intializing string
print(conList(list))

Output :

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
= RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test.py =
Hello fellow earthlings i am archit
>>> 

Output Explanation:

= RESTART: C:/Users/ARCHIT/AppData/Local/Programs/Python/Python37-32/test.py =
Hello fellow earthlings i am archit

The output is as it is expected. This initialised list list1 = [“Hello”,” fellow”, ” earthlings “,”i am archit”] is converted in string Hello fellow earthlings i am archit.
Similarly, whatever in the list can be changed into string using this program and initialising the list.

Conclusion:

The program is running fine.

Thank you for learning, reading and copying source of this Python program to convert list to string. This program contains python function definition, for iterative statement , list initialization and printing. This program is for B Tech engineers and also for expert programmer as it is used in various time in python projects. Below are the links of more programs like this,
/category/python-programs/
Python Projects for Class 12 with Source Code (Mysql Connectivity) – CS Study

Leave a Comment

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