Is it possible to modify variables in if statements, loops, and function calls in Python like you can in C and Java?
Ex:
i=0
while((i+=1)<10): #invalid syntax
print(i)
If not why is that?
Is it possible to modify variables in if statements, loops, and function calls in Python like you can in C and Java?
Ex:
i=0
while((i+=1)<10): #invalid syntax
print(i)
If not why is that?
as long as the datatype is mutable
def modified(data):
data['a'] = 5
x = {'b':7}
modified(x)
print(x)
def increment_a(data):
data['a'] += 1
return data['a']
x = {'a':1}
while increment_a(x) < 10:
print(x)
however strings and integers are immutable