用于克隆或复制列表的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]
热门推荐
1 十月简短祝福语
10 家长祝福语大全简短内容
11 50多岁生日简短祝福语
12 喜事敬酒祝福语简短精辟
13 孙子结婚祝福语大全简短
14 农民朋友发财祝福语简短
15 恭贺新婚文案祝福语简短
16 年前幸福祝福语大全简短
17 新春进门祝福语大全简短
18 朋友花篮开业祝福语简短