I'm having some trouble looping over a list of variables. Specifically, I want to write a function that returns info about the running system. Below is an example of a for loop I tried:
def sysInfo():
cpu = psutil.cpu_count()
memory = psutil.virtual_memory()
disk = psutil.disk_usage('/')
specs = [cpu, memory, disk]
for c in specs:
return c
print sysInfo()
The function runs with no errors but only returns the first item in the list, which leads me to conclude that the loop only executes once. However if I switch the return statement with print (and call the function instead of printing it) then all the items of the list gets printed.
My question then becomes: Why does the loop only give the first item in the list with return, but print gives all of them?