0

I am fairly new to python. I was trying to store raw input to an empty list. And apparently, the input didn't go into the empty list. Then what went wrong?

Latitude = []
Longitude = []
print Latitude #**THIS GIVES []**

Lat_input = raw_input("What is your latitude:")
Latitude = Latitude.append(Lat_input)
print Latitude # **HERE I GOT NONE**

Long_input = raw_input("WHat is your longitude:")
Longitude = Longitude.append(Long_input)

I looked up some other postings, still didn't figure out what I did wrong. What did I miss? Why is my list gone? Thanks, guys!

pradyunsg
  • 18,287
  • 11
  • 43
  • 96
WHZW
  • 445
  • 6
  • 10
  • possible duplicate of [list append gives None as result](http://stackoverflow.com/questions/26151795/list-append-gives-none-as-result) – Charles Duffy Oct 11 '14 at 00:13

1 Answers1

4

append is an in-place operation; it doesn't return a value.

Just run:

Longitude.append(Long_input)

...not

Longitude = Longitude.append(Long_input)

This is by design and intent: Returning None rather than a value makes it clear that a function is being called for its side effects rather than its return value.

If you didn't want to modify the existing Longitude in place, but instead wanted to create a new list with the new item appended, then you might instead use:

Longitude = Longitude + [Long_input]
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441