x = list(range(10)) print(‘整数输出:‘ ,end=‘‘) for i in x: print(i,end=‘ ‘) print(‘\n整数输出2:‘,end=‘‘) for i in x: print(f‘{i:02d}‘,end=‘-‘) print(‘\n整数输出3:‘,end=‘‘) for i in x[:-1]: print(f‘{i:02d}‘,end=‘-‘) print(f‘{x[-1]:02d}‘) print(‘\n字符输出1:‘,end=‘‘) y1 = [str(i)for i in range(10)] print(‘-‘.join(y1)) print(‘字符输出2:‘,end=‘‘) y2 = [str(i).zfill(2)for i in range(10)] print(‘-‘.join(y2))
x= list(range(1,10)) y = [chr(i)for i in range(97,97+26)] z = [i.upper()for i in y] s = x+y+z print(s)
import random import string print(‘\n用列表存储随机整数:‘) ls = [random.randint(1,100)for i in range(5)] print(ls) print(‘\n用集合存储随机整数:‘) s = {random.randint(1,100)for i in range(5)} print(s) print(‘\n\n字母串:‘,end=‘‘) alpha = string.ascii_letters print(alpha) print(type(alpha)) print(‘\n字母串:‘,end=‘ ‘) digits = string.digits print(digits) print(type(digits))
import random print(‘‘) while True: s = {random.randint(1,100)for i in range(5)} print(s) if len(s)<5: break
原文:https://www.cnblogs.com/liangshanfeng/p/14695318.html