0

when I am run this in IDE, List is created but empty list, how can I solve this?

>>> def findnum(n,m):
          print('hellow')
          l=list(range(n,m))
>>> findnum(1,10)
hellow
>>> l
[]
Cœur
  • 37,241
  • 25
  • 195
  • 267
C Kondaiah
  • 72
  • 8
  • You are not returning anything from the function so `l` is local to `findnum()`... try: `l = findnum(1, 10)` and in `findnum()` end with `return l`. This is elementary programming, so you may need to read more introductory materials. – AChampion Apr 18 '17 at 14:18
  • is this working same as in the separate file writing, i mean when typing and save in a file like findnum.py – C Kondaiah Apr 18 '17 at 14:47
  • Possible duplicate of [Access a function variable outside the function without using "global"](https://stackoverflow.com/questions/19326004/access-a-function-variable-outside-the-function-without-using-global) – SiHa Jan 07 '19 at 11:11

1 Answers1

1

Return the list from the function and take it in a separate variable. Here, l is list having data only in the scope of function. The following code snippet might help:

>>> def findnum(n,m):
      print('hellow')
      l=list(range(n,m))
      return l
>>> l = findnum(1,10)
noobita
  • 67
  • 11