"Similar to mathematical set notation (e.g., $\\\\{ x ~|~ x \\in \\mathbf R \\land x > 0\\\\}$), we can create lists."
"Similar to mathematical set notation (e.g., $\\{ x ~|~ x \\in \\mathbf R \\land x > 0\\}$), we can create lists."
]
]
},
},
{
{
...
@@ -2969,7 +2969,94 @@
...
@@ -2969,7 +2969,94 @@
"Everything is an object\n",
"Everything is an object\n",
"---\n",
"---\n",
"\n",
"\n",
"In Python, all values are objects. Objects have properties and methods. You can explore them using `dir(obj)`, or by typing `obj.<tab>` in the IPython interpreter."
"* In Python, all values are objects.\n",
"* Objects can have properties and methods. \n",
"* You can explore them using `dir(o)`, or by typing `o.<tab>` in the IPython interpreter."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"dir('abc')[-10:]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"text": [
"['rstrip',\n",
" 'split',\n",
" 'splitlines',\n",
" 'startswith',\n",
" 'strip',\n",
" 'swapcase',\n",
" 'title',\n",
" 'translate',\n",
" 'upper',\n",
" 'zfill']"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"help('abc'.split)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Help on built-in function split:\n",
"\n",
"split(...)\n",
" S.split([sep [,maxsplit]]) -> list of strings\n",
" \n",
" Return a list of the words in the string S, using sep as the\n",
" delimiter string. If maxsplit is given, at most maxsplit\n",
" splits are done. If sep is not specified or is None, any\n",
" whitespace string is a separator and empty strings are removed\n",
" from the result.\n",
"\n"
]
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"'abc abc abc'.split()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 16,
"text": [
"['abc', 'abc', 'abc']"
]
}
],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Properties and methods that start and end with `__` have a special meaning and are normally not used directly."
]
]
},
},
{
{
...
@@ -2984,9 +3071,37 @@
...
@@ -2984,9 +3071,37 @@
"===\n",
"===\n",
"\n",
"\n",
"Classes\n",
"Classes\n",
"---"
"---\n",
"\n",
"* You can define your own types of objects with classes.\n",
"* The constructor method is called `__init__`.\n",
"* Initialize properties in the constructor.\n",
"* Every method recieves the object (class instance) as its first argument."