Python循环实现位置交换

四小花旦:杨幂,郑爽,杨紫,赵丽颖,编写程序交互第一的宝座,实现结果如下:

['郑爽', '杨紫', '赵丽颖', '杨幂']
['杨紫', '赵丽颖', '杨幂', '郑爽']
['赵丽颖', '杨幂', '郑爽', '杨紫']
['杨幂', '郑爽', '杨紫', '赵丽颖']

star= ['杨幂','郑爽','杨紫','赵丽颖']
for i in range(4):
    star1 = star.pop(0)  # 运用pop()函数,同时完成提取和删除。
    star.append(star1)  # 将移除的student1安排到最后一个座位。
    print(star)

#用while循环
students = ['杨幂','郑爽','杨紫','赵丽颖']
i=0
while i<4:
    i+= 1
    student1=students.pop(0) #移除第一个
    students.append(student1)
    print(students)

  

原文地址:https://www.cnblogs.com/ITester520/p/12018480.html