How to Print Python Lists as String

Question:

I would like to know how to print python lists as String instead of list.
When I add the three lists I get the following result

['a', 'b', 'c', 'd', '0', '1', '!', '#']

I want this output:

abcd01!#

import random
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

print("Welcome to the PyPassword Generator!")
nr_letters= int(input("How many letters would you like in your password?n")) 
nr_symbols = int(input(f"How many symbols would you like?n"))
nr_numbers = int(input(f"How many numbers would you like?n"))

#Eazy Level - Order not randomised:
#e.g. 4 letter, 2 symbol, 2 number = JduE&!91


letter_pick = letters[0:nr_letters]
number_pick = numbers[0:nr_symbols]
symbol_pick = symbols[0:nr_numbers]

print (letter_pick+number_pick+symbol_pick)`

expecting

abcd01!#

instead of

['a', 'b', 'c', 'd', '0', '1', '!', '#']
Asked By: Saqib Munir

||

Answers:

You can use join to join all element of list.

print(''.join(letter_pick+number_pick+symbol_pick))

if you only want to print the data. Use this.

print(*(letter_pick+number_pick+symbol_pick), sep='')
Answered By: codester_09
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.