| |

VerySource

 Forgot password?
 Register
Search
View: 30|Reply: 3

Immutable variables in python

[Copy link]

2

Threads

4

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

Post time: 2020-3-23 16:30:01
| Show all posts |Read mode
Why are there immutable variable types? ? Isn't this troublesome?

Such as:
num = 1
num = num + 2

In the above simple sentence, an int object is generated twice. Isn't this slower using python? ?

Is it slower to modify the value of a variable than to generate a variable? ?

Generating a variable is not more of a tool to do. Don't understand
Reply

Use magic Report

0

Threads

1

Posts

1

Credits

Newbie

Rank: 1

Credits
1

 United States

Post time: 2020-5-23 13:03:24
| Show all posts
A variable is a bunch of addresses in the RAM, changing the value is changing the value of whatever is stored in the bunch of addresses. Generating a variable is saving RAM storage for that variable, then your code can put information in those storage spaces in RAM.
Reply

Use magic Report

0

Threads

33

Posts

19

Credits

Newbie

Rank: 1

Credits
19

 China

Post time: 2020-7-3 09:15:01
| Show all posts
In C++, there is this situation
int a = 1;
a = a++ + ++a;
Variables are immutable or can avoid ambiguity
Reply

Use magic Report

2

Threads

4

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 China

 Author| Post time: 2020-7-4 22:30:01
| Show all posts
Are there any other benefits? It is too much for this sacrifice. :)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list