anyone can explain why when we declare as list, it will cross different method, but if declare as int, it can only use inside of method.
Thanks
anyone can explain why when we declare as list, it will cross different method, but if declare as int, it can only use inside of method.
Thanks
In the example where you have l
and n
as ints, you aren't actually modifying l
or n
before you print them. You are incrementing p
and k
but then since p
and k
aren't assigned to anything you are throwing the computation away.
Additionally, ints
in Python are immutable. So, if you wanted to store an updated value, your class should have properties that you update accordingly such as self.l
and self.n
.