0%
自此无心爱良夜,任他明月下西楼。
按逗号分隔列表
1 2 3
| L = [1,2,3,4,5] s1 = ','.join(str(n) for n in L) print s1
|
有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
1 2 3 4 5
| for i in range(1,5): for j in range(1,5): for k in range(1,5): if( i != k ) and (i != j) and (j != k): print i,j,k
|
交换两个变量
1 2 3 4 5 6 7 8 9 10 11 12
| def exchange(a,b): a,b = b,a return (a,b)
if __name__ == '__main__': x = 10 y = 20 print('x = %d,y = %d' % (x,y))
x,y = exchange(x,y)
print('x = %d,y = %d' % (x,y))
|