简体   繁体   中英

Function Outputs None instead of Return

I'm new to functions and cannot figure out why this returns 'None' Essentially the State is a number, so this should input the state and spit out the population. I'll change the format to be more vague and helpful for all once I understand better. Thanks!

def ca_pov(state, spending=0):
  state = person[person.state==state].copy(deep=True)
  total_population = state.weight.sum()

  return
  total_population

print(ca_pov(11))

the total_population was not returned. You have to write the return keyword and the data you want to return next to it.

def ca_pov(state, spending=0):
  state = person[person.state==state].copy(deep=True)
  total_population = state.weight.sum()

  return total_population

print(ca_pov(11))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM