Skip to main content

Command Palette

Search for a command to run...

#13 - Python Destructuring

By Ifeanyi Omeata

Published
1 min read
#13 - Python Destructuring
I

Hi, I am a Software Developer of 3-4 years specialising in React, Javascript, Node, NextJS, Express, Python, Django, Fast API, SQL and a few other technology stack, with a good background in Networking and Cloud Infrastructure. I am working to become a DevOps Solutions Engineer and happily married to my long time girlfriend.


Topics:


1. Divmod Method
2. Destructuring Values
3. Destructuring Lists
4. Destructuring - Ignoring values


1. Divmod Method


>>Return to Menu

#divmod = Division|Modulus
a = divmod(10, 2)
print(a)

b, c = divmod(10, 2)
print(b)
print(c)

image.png


2. Destructuring Values


>>Return to Menu

#Destructuring values
a, b = (1, 2)
print(a)
print(b)

image.png


3. Destructuring Lists


>>Return to Menu

#Destructuring lists
sum = [2,3,4,5,6]
a,b,*c = sum
print(a)
print(b)
print(c)

Same as:

#Destructuring lists
sum = [2,3,4,5,6]
a = sum[0]
b = sum[1]
c = sum[2:]
print(a)
print(b)
print(c)

image.png


4. Destructuring - Ignoring values


>>Return to Menu
Example 1:

#Destructuring - Ignoring Values
sum = [2,3,4,5,6]
a,_,*b = sum
print(a)
print(b)

Example 2:

#Destructuring - Ignoring Values
sum = [2,3,4,5,6]
a,*_,b = sum
print(a)
print(b)

image.png

#End


Hope you enjoyed this! :) Follow me for more contents...


Get in Touch:
www.ifeanyiomeata.com
contact@ifeanyiomeata.com

Youtube: https://www.youtube.com/c/IfeanyiOmeata
Linkedin: https://www.linkedin.com/in/omeatai/
Twitter: https://twitter.com/iomeata
Github: https://github.com/omeatai/
Stackoverflow: https://stackoverflow.com/users/2689166/omeatai
Hashnode: https://hashnode.com/@omeatai
Medium: https://medium.com/@omeatai
© 2022

LEARN PYTHON/DJANGO

Part 24 of 37

Learn Python and Django the easy way!..... PYTHON | DJANGO | FASTAPI

Up next

#12 - Python Errors

By Ifeanyi Omeata