开发者

Python: Cannot Assign Function Call

I a开发者_开发知识库m having a problem such as:

def function (number):
      for number in list:
          number = number + 1

For example function(1): for number in range(1,5): number = number + 1

Error come back as "can't assign function call" I would like to use that variable as a value for further calculations.

Help!


I think you have two problems. First, you are not naming your function or declaring it properly; you should do this:

def f(number):
   ...

Second, you are naming the function parameter number but on the next line you seem to be treating list as though it were the parameter. I think you mean to do this instead:

def f(list):
  for number in my_list:
  ...


Functions in python are defined using the def keyword:

def function_name(number):
  for number in my_list:
      number = number + something


you have to use def to define a function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜