Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python destructuring

head, *tail = [1, 2, 3, 4, 5]

print(head)  # 1
print(tail)  # [2, 3, 4, 5]
Comment

python destructor

# Python program to illustrate destructor
class Employee:
 
    # Initializing
    def __init__(self):
        print('Employee created.')
 
    # Deleting (Calling destructor)
    def __del__(self):
        print('Destructor called, Employee deleted.')
 
obj = Employee()
del obj
Comment

python destructor

# Python program to illustrate destructor
 
class A:
    def __init__(self, bb):
        self.b = bb
 
class B:
    def __init__(self):
        self.a = A(self)
    def __del__(self):
        print("die")
 
def fun():
    b = B()
 
fun()
Comment

python destructuring

x, y = (5, 11)

people = [
  ("James", 42, "M"),
  ("Bob", 24, "M"),
  ("Ana", 32, "F")
]

for name, age, gender in people:
  print(f"Name: {name}, Age: {age}, Profession: {gender}")

# use _ to ignore a value
person = ("Bob", 42, "Mechanic")
name, _, profession = person

head, *tail = [1, 2, 3, 4, 5]

print(head)  # 1
print(tail)  # [2, 3, 4, 5]

*head, tail = [1, 2, 3, 4, 5]

print(head)  # [1, 2, 3, 4]
print(tail)  # 5

head, *middle, tail = [1, 2, 3, 4, 5]

print(head)    # 1
print(middle)  # [2, 3, 4]
print(tail)    # 5

head, *_, tail = [1, 2, 3, 4, 5]
print(head, tail)  # 1 5

from operator import itemgetter

params = {'a': 1, 'b': 2, 'c': 3}

# return keys a and c
a, c = itemgetter('a', 'c')(params)

print(a, c)
# output 1 3
Comment

PREVIOUS NEXT
Code Example
Python :: python googledriver download 
Python :: pandas.DataFrame.fillna 
Python :: Python NumPy append Function Syntax 
Python :: how to find missing item in a list 
Python :: django 
Python :: seaborn pandas annotate 
Python :: python choose function 
Python :: python set to list 
Python :: discard python 
Python :: tkinker 
Python :: matplotlib.pyplot 
Python :: ttktheme example 
Python :: streamlit - Warning: NumberInput value below has type int so is displayed as int despite format string %.1f. 
Python :: how list ul li with python scraping 
Python :: custom pylatex command 
Python :: pandas excelfile 
Python :: numpy combine two arrays selecting min 
Python :: where to put capybara default wait time 
Python :: First Python Program: Hello World 
Python :: ndarray python 
Python :: save artist animation puython 
Python :: set index values pandas 
Python :: how to get maximum value of number in python 
Python :: df dtype 
Python :: where is a package stored python 
Python :: convert pdf to excel python 
Python :: how to skip error python 
Python :: hide verbose in pip install 
Python :: __add__ 
Python :: python manually trigger exception 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =