python中实现数字的全排列

 

001、假定数字为3

[root@pc1 test1]# ls
test.py
[root@pc1 test1]# cat test.py           ## 测试程序
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

for i in range(1,4):
        for j in range(1,4):
                if j == i:
                        continue
                for k in range(1,4):
                        if k == j or k == i:
                                continue
                        print(str(i) + str(j) + str(k))
[root@pc1 test1]# python3 test.py      ## 程序运行结果
123
132
213
231
312
321

 

.

 

posted @ 2023-09-28 20:25  小鲨鱼2018  阅读(29)  评论(0编辑  收藏  举报