Sunday, January 5, 2014

Print list of int, and String

This example print list of int, and String:
Print list of int, and String
Print list of int, and String

#generate random 5 number
import random

list=[]     #init a empty list

for x in range(0, 5):
    random_number = random.randint(0, 10)
    print(random_number)
    list.append(random_number)  #append random number to list
    
#print all elements
print('[%s]' % ', '.join(map(str, list)))

strList = ['abc', 'def', 'ghi', 'jkl']
#join strings in list, with ', ' in between each element.
print(', '.join(strList));