[Tutor] Advice Please
David Rock
david at graniteweb.com
Mon Jun 15 16:23:30 EDT 2020
* John Weller <john at johnweller.co.uk> [2020-06-15 15:21]:
> pass the parameters to the function by reference so as to be able to
> access the values outside the function however I understand that this
> is not available in Python. Can Python return multiple values,
> (return temperature, humidity)? If not I could make the variables
yes, it's possible to return multiple values
temp, humidity = read_temp_humidity()
Where the return statement within your function will look like:
return temp, humidity
> global (not recommended but as these values are fundamental to the
> whole program then perhaps acceptable) or use a compound data
> structure such as a dictionary or create a class just to hold the
> data? My question is – what do you recommend?
Globals or returning a single dictionary would also work. Generally, I
use a dict if there are going to be many element to return, and a tuple
if only a few (eg, just temp and humidity as above).
> Can anyone recommend a book that I can use as a reference to perhaps
> answer some question without having to bother you guys 😊. I’ve
That's hard to do without more of a solid understanding of your tastes
and needs. There's the Python Books list on python.org
https://wiki.python.org/moin/PythonBooks
There are several good web-based "books" as well "Dive Into Python"
usually bubbles to the top: https://diveintopython3.net/
I honestly do most of my stuff searching within the online docs.
--
David Rock
david at graniteweb.com
More information about the Tutor
mailing list