Computer >> 컴퓨터 >  >> 프로그램 작성 >> 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]