Skip to content

Commit

Permalink
operators & casting ♊
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyear committed Jan 31, 2016
1 parent 0e85583 commit 2e26553
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

- [X] `import this`
- [X] Basic Syntax
- [ ] Native Datatypes
- [X] Native Datatypes
- [X] Number
- [X] String
- [X] Boolean
Expand All @@ -35,7 +35,7 @@
- [X] Tuple
- [X] Set
- [X] Dict
- [ ] Operators & Casting
- [X] Operators & Casting
- [X] Flow Control
- [X] `if/elif/else`
- [X] `for...in...`
Expand Down
201 changes: 189 additions & 12 deletions notebooks/py3-in-one-pic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 20,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -116,6 +116,132 @@
"print(f == e) # True"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2\n",
"0\n",
"9\n",
"1.25\n",
"1024\n",
"1\n",
"1\n"
]
}
],
"source": [
"## Operators: + - * / ** // %\n",
"print(1 + 1)\n",
"\n",
"print(2 - 2)\n",
"\n",
"print(3 * 3)\n",
"\n",
"print(5 / 4)\n",
"\n",
"print(2 ** 10)\n",
"\n",
"print(5 // 4)\n",
"\n",
"print(5 % 4)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"float(x) -> floating point number\n",
"\n",
"Convert a string or number to a floating point number, if possible.\n",
"3.0\n",
"3.0\n",
"3.14\n"
]
}
],
"source": [
"## Casting\n",
"### Integer -> Float\n",
"print(float.__doc__)\n",
"\n",
"print(float(3))\n",
"print(3 / 1)\n",
"print(float(\"3.14\"))"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"int(x=0) -> integer\n",
"int(x, base=10) -> integer\n",
"\n",
"Convert a number or string to an integer, or return 0 if no arguments\n",
"are given. If x is a number, return x.__int__(). For floating point\n",
"numbers, this truncates towards zero.\n",
"\n",
"If x is not a number or if base is given, then x must be a string,\n",
"bytes, or bytearray instance representing an integer literal in the\n",
"given base. The literal can be preceded by '+' or '-' and be surrounded\n",
"by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n",
"Base 0 means to interpret the base from the string as an integer literal.\n",
">>> int('0b100', base=0)\n",
"4\n"
]
}
],
"source": [
"### Float -> Integer\n",
"print(int.__doc__)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"3\n",
"10\n",
"10\n"
]
}
],
"source": [
"print(int(3.14)) # 3\n",
"print(int(\"3\", base = 10)) # 3\n",
"print(int(\"1010\", base = 2)) # 10\n",
"print(int(\"0b1010\", base = 0)) # 10"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -195,6 +321,68 @@
"print('{0}:{1}'.format(s[0], s[-2])) # 学:习"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"abc.xyz\n"
]
}
],
"source": [
"## Operator: +\n",
"print(\"abc\" + \".\" + \"xyz\")"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"str(object='') -> str\n",
"str(bytes_or_buffer[, encoding[, errors]]) -> str\n",
"\n",
"Create a new string object from the given object. If encoding or\n",
"errors is specified, then the object must expose a data buffer\n",
"that will be decoded using the given encoding and error handler.\n",
"Otherwise, returns the result of object.__str__() (if defined)\n",
"or repr(object).\n",
"encoding defaults to sys.getdefaultencoding().\n",
"errors defaults to 'strict'.\n",
"3.14\n",
"3\n",
"[1, 2, 3]\n",
"(1, 2, 3)\n",
"{1, 2, 3}\n",
"{'python': '*.py', 'javascript': '*.js'}\n"
]
}
],
"source": [
"## Casting\n",
"print(str.__doc__)\n",
"\n",
"print(str(3.14))\n",
"print(str(3))\n",
"print(str([1,2,3]))\n",
"print(str((1,2,3)))\n",
"print(str({1,2,3}))\n",
"print(str({'python': '*.py', 'javascript': '*.js'}))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -771,8 +959,6 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### II. Operators & Casting\n",
"\n",
"### III. Flow Control\n",
"\n",
"#### If"
Expand Down Expand Up @@ -987,15 +1173,6 @@
"### VIII. Standard Libraries"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file modified py3 in one pic.mindnode/QuickLook/Preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified py3 in one pic.mindnode/contents.xml
Binary file not shown.
Binary file modified py3 in one pic.mindnode/viewState.plist
Binary file not shown.
Binary file modified py3 in one pic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2e26553

Please sign in to comment.