Skip to content

Instantly share code, notes, and snippets.

@xiaopeng163
Created November 26, 2016 14:00
Show Gist options
  • Save xiaopeng163/dd44f13def2fa8976168533f9589c815 to your computer and use it in GitHub Desktop.
Save xiaopeng163/dd44f13def2fa8976168533f9589c815 to your computer and use it in GitHub Desktop.
~~~ clear

➜  ~ python
Python 2.7.10 (default, Jul 30 2016, 18:31:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>
>>> ^D
➜  ~ clear

➜  ~ python
Python 2.7.10 (default, Jul 30 2016, 18:31:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = (1, 2, 4)
>>> a
(1, 2, 4)
>>> type(a)
<type 'tuple'>
>>> b = [1, 2, 4]
>>> b
[1, 2, 4]
>>> type(b)
<type 'list'>
>>>
>>> b.append(5)
>>> b
[1, 2, 4, 5]
>>>
>>>
>>> c = {}
>>> type(c)
<type 'dict'>
>>> c = {'xiaopeng': 30}
>>> c
{'xiaopeng': 30}
>>> c['xiaopeng']
30
>>> c['new_person'] =  40
>>>
>>> c
{'new_person': 40, 'xiaopeng': 30}
>>> c['new_person']
40
>>>
>>>
>>> len(c)
2
>>>
>>> len(b)
4
>>> len(a)
3
>>> b
[1, 2, 4, 5]
>>>
>>>
>>> b[1:]
[2, 4, 5]
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> for loop
  File "<stdin>", line 1
    for loop
           ^
SyntaxError: invalid syntax
>>> for loop
  File "<stdin>", line 1
    for loop
           ^
SyntaxError: invalid syntax
>>>
>>>
>>> b
[1, 2, 4, 5]
>>>
>>>
>>>
>>>
>>>
>>> for i in b:
...     print i
...
1
2
4
5
>>> range(1,5)
[1, 2, 3, 4]
>>> d = range(1, 5)
>>> d
[1, 2, 3, 4]
>>> type(d)
<type 'list'>
>>>
>>>
>>> d = range(1,5)
>>> d
[1, 2, 3, 4]
>>>
>>>
>>>
>>> d = range(1,5,2)
>>> d
[1, 3]
>>>
>>>
>>>
>>> for i in range(1,5):
...     print i
...
1
2
3
4
>>> c
{'new_person': 40, 'xiaopeng': 30}
>>> c
{'new_person': 40, 'xiaopeng': 30}
>>>
>>>
>>>
>>>
>>>
>>> for key in c:
...     print key
...
new_person
xiaopeng
>>>
>>>
>>> for key in c:
...     print key, c[key]
...
new_person 40
xiaopeng 30
>>>
>>>
>>> c
{'new_person': 40, 'xiaopeng': 30}
>>> c.keys()
['new_person', 'xiaopeng']
>>>
>>>
>>> for key in c.keys():
...     print key
...
new_person
xiaopeng
>>>
>>>
>>>
>>>
>>>
>>> print c.keys()
['new_person', 'xiaopeng']
>>> print c.keys(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: keys() takes no arguments (1 given)
>>>
>>>
>>>
>>> print c.keys()[0]
new_person
>>> print c.keys()[2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> print c.keys()[1]
xiaopeng
>>>
>>>
>>> s = 'xiaopeng'
>>> s
'xiaopeng'
>>>
>>>
>>> type(s)
<type 'str'>
>>> s[0]
'x'
>>> s[1]
'i'
>>>
>>>
>>> for i in s:
...     print i
...
x
i
a
o
p
e
n
g
>>> b.append(5)
>>> b
[1, 2, 4, 5, 5]
>>>
>>>
>>> b1= [11,22,33]
>>>
>>>
>>> b + b1
[1, 2, 4, 5, 5, 11, 22, 33]
>>>
>>>
>>>
>>>
>>> n = 1
>>> type(n)
<type 'int'>
>>>
>>> n = '1'
>>> type(n)
<type 'str'>
>>>
@xiaopeng163
Copy link
Author

xiaopeng163 commented Dec 18, 2016

$ docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS            PORTS           NAMES
4791db4ff0ef        xiaopeng163/redis:0.1   "/usr/bin/redis-serve"   20 minutes ago      Up 20 minutes     6379/tcp        demo
$ docker stop demo
demo
$ docker ps -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                     PORTS    NAMES
4791db4ff0ef        xiaopeng163/redis:0.1   "/usr/bin/redis-serve"   20 minutes ago      Exited (0) 7 seconds ago            demo
$ docker rm demo
demo
$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment