-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
namedtuple, userlist
userlist : 보다 쉬운 메소드 재정의 가능.(리스트의 메소드를 override하지 않고 접근 가능하기에)
namedtuple : attribute로 접근 가능. -> immutable, 사용x, 새 class생성.
# Python program to demonstrate
# userlist
from collections import UserList
# Creating a List where
# deletion is not allowed
class MyList(UserList):
# Function to stop deletion
# from List
def remove(self, s = None):
raise RuntimeError("Deletion not allowed")
# Function to stop pop from
# List
def pop(self, s = None):
raise RuntimeError("Deletion not allowed")
# Driver's code
L = MyList([1, 2, 3, 4])
print("Original List")
# Inserting to List"
L.append(5)
print("After Insertion")
print(L)
# Deleting From List
L.remove()
Reactions are currently unavailable

