A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/070831.html below:

Python Programming Ettiquette

Python Programming Ettiquettezzzzz zzizz_ at notmail.com
Thu Apr 12 01:45:00 EDT 2001
If I want to change a variable value from within a function I believe
I have two options:

a) Directly modify the parameter:
x=[1,2,3]
def add4tolist(inputlist):
   inputlist.append(4)
add4tolist(x)
x
[1,2,3,4]

b) Return the result, keeping the passed parameter untouched:
x=[1,2,3]
def add4tolist(inputlist):
   return (inputlist[:]).append(4)
x=add4tolist(x)
x
[1,2,3,4]

a) is simpler, however, it only works on immutable type
b) is more general, however, you still have to be careful about
accidently modifying mutable parameters.

Is there any accepted programming etiquette on how to best go about
this?

Regards,

zzzzz.
---------------------

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4