Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created January 3, 2018 05:23
Show Gist options
  • Save laixintao/5cf1a662449ef56879b2ebcac189643f to your computer and use it in GitHub Desktop.
Save laixintao/5cf1a662449ef56879b2ebcac189643f to your computer and use it in GitHub Desktop.
~/Downloads  ipython
Python 3.6.3 (default, Nov 3 2017, 14:41:25)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: i = 'foo'
In [2]: [i for i in range(10)]
Out[2]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
In [3]: i
Out[3]: 'foo'
In [4]: for i in range(10):
...: print(i)
...:
0
1
2
3
4
5
6
7
8
9
In [5]: i
Out[5]: 9
In [6]: exit
~/Downloads  python2.7
Python 2.7.14 (default, Sep 25 2017, 09:54:19)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> i = 'foo'
>>> [i for i in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> i
9
>>> i = 'foo'
>>> for i in range(10):
... print(i)
...
0
1
2
3
4
5
6
7
8
9
>>> i
9
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment