Functional Programming in Python: Immutable Data Structures

preview_player
Показать описание

In this Python tutorial you'll learn the basics of functional programming in Python and how you can use immutable data structures to represent data in your programs.

First, we'll go over what functional programming (FP) is from a computer science perspective and how it compares to other programming paradigms, like object-oriented programming (OOP), or procedural programming.

You'll learn how a functional programming style avoids side-effects and changing state in your programs by focusing on the application of mathematical functions as its core primitive.

Next, we'll take a simple data set and represent it inside our example program using immutable data structures (tuples and namedtuples from the "collections" module built into Python). Immutable data structures cannot be modified in-place and this can help reduce bugs.

This is part of a series of Python functional programming tutorials that I'm recording so stay tuned for the next instalment.

Also, be sure to check out these associated articles if you want to dive deeper into the subject:

* * *

FREE Python Coding Tutorials & News:
Рекомендации по теме
Комментарии
Автор

Can you do a video for beginners explaining the difference between procedural, functional and OOP. and any other styles of programming. Explaining the pros and cons of each and were you would use each.

First_Principals
Автор

Excellent video Dan, thank you. Especially the way you show the data set in mutable data structures, and then recast the same data in immutable data structures in order to force the error, showing the exact difference. Nice.

dixone
Автор

Nice tutorial but and what python interpreter is ? this You customized it ?

mohanbarman
Автор

Can we say that namedtuple as immutable data strcture, as it has one method _replace, which basically update the values & return new instance.
namedtuple._replace(**kwargs)

learn.dataengineering
Автор

Great tutorial series... pls keep on adding...btw-which python editor you are using here ? Thanks

absar
Автор

Thanx for the video! Loved the REPL :) Quick question, what about `Scientist(name='foo', field=None, born='1800', nobel=1)` type of attribute? `nobel` becomes `int` and it will kind of break our data's structure right? I feel like, create a class and make the restrictions there... What do you think?

Автор

Is there a way to use a Class instead of a named tuple? Would we gain anything? And is there a benefit to using a named tuple here instead? Also the daily emails are pretty awesome. I much rather read that than waste my time on social media, so thanks!

imxron
Автор

Great explanation for immutable data structures. Thanks.

naeemkhoshnevis
Автор

Interesting, u should keep posting more videos like this

MrJos
Автор

I'm a Python dev wannabe and your YT video are awesome! Plus, it's a great way to promote your Python Tricks book, since your videos clearly explain each topic without confusing me, I bet your book is even better and with more Python information. I'm going to buy it before the price increases. P.S. no this is not a paid or free advertisement. lol I just want everyone to know they have more ways to learn Python from Dan the Man.

pythondjango
Автор

Very interesting thanks Dan! Look forward to map reduce and stuff!

sunnz
Автор

How did you set up your terminal to have code highlighting?

serhiy
Автор

I always use dictionaries, not sure when I should rather use immutable structures such as named tuples... Also, would it be a good idea to use class objects instead of named tuples?... I think I will learn a lot! Thank you!

roshcoben
Автор

wow! You use my suggestion of women in science :D :D
Great tutorial btw!

OmarMiranda
Автор

why did record video with such low volume??

jaleshjalesh
Автор

2:40 Did you mean SQL? Because if that's the case, that's not how it is pronounced.

CarlosWashingtonMercado
Автор

Are you Dutch? You sound like a Dutch person trying hard to sound American. Thanks for the video though.

funkmaster