From the course: Functional Programming with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Immutability

Immutability - Python Tutorial

From the course: Functional Programming with Python

Start my 1-month free trial

Immutability

- [Instructor] The first major concept of functional programming is immutability. And it's a concept that may surprise a lot of people at first. You see most programmers learned early on that you could assign a value to a variable, for example we can define a variable called X and store the value five in it, and then later on we can change its value again and so on. However, in functional programming this is not allowed. When we say that X is equal to five, we mean that for the rest of the program, X will only ever be five. Conceptually, there should be no way for us to change it. In short, immutability means that most of the values in our program should be treated as constants. And since unlike many other languages, Python doesn't have a dedicated constant keyword for preventing variables from changing, this means that we have to be very careful and get into the habit of not changing variables once we've assigned a…

Contents