python 复制列表内容_用于克隆或复制列表的Python程序。

在该程序中给出了用户输入列表。我们的任务是复制或克隆列表。这里我们使用切片技术。在这种技术中,我们将复制列表本身以及参考。此过程也称为克隆。

算法Step 1: Input elements of the array.

Step 2: then do cloning using slicing operator(:).

范例程式码# Python program to copy or clone a list

# Using the Slice Operator

def copyandcloning(cl):

copylist = cl[:]

return copylist

# Driver Code

A=list()

n1=int(input("Enter the size of the List ::"))

print("Enter the Element of List ::")

for i in range(int(n1)):

k=int(input(""))

A.append(k)

clon = copyandcloning(A)

print("Original or Before Cloning The List Is:", A)

print("After Cloning:", clon)

输出结果Enter the size of the  List ::6

Enter the Element of  List ::

33

22

11

67

56

90

Original or Before Cloning The List Is: [33, 22, 11, 67, 56, 90]

After Cloning: [33, 22, 11, 67, 56, 90]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值