Q: Storing pyplot object in variable Please refer to the following code.
>>> p = plt.plot(year, rank)
>>> p.show()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'show'
>>> plt.plot(year, rank)
[<matplotlib.lines.Line2D object at 0x7f3b56443890>]
>>> plt.show()

When I try to store plt in a variable p, it showing the AttributeError:
But when directly use plt.show(), it's working. I am not able to understand the difference.
I am using python 2.7 in Ubuntu 16.4, and running the program from terminal.

A: plt.plot(x,y) returns a list of Line2D objects. You store this list in a variable p. As the error tells you, 'list' object has no attribute 'show'. This can be taken literally, because show() is a function in the matplotlib.pyplot module and any normal python list does not even know about the existence of matplotlib. 
You may of course still store the list in a variable, but in order to show the plot you need to use plt.show() independent of where you stored the return of any plotting commands
import matplotlib.pyplot as plt
p = plt.plot(x,y)
plt.show()

