You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"This snippit was written by [Chris R. Albon](http://www.chrisralbon.com/) and is part of his collection of [well-documented Python snippits](https://github.com/chrisalbon/code_py). All code is written in Python 3 in iPython notebook and offered under the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/\"><img alt=\"Creative Commons License)."
23
+
]
24
+
},
25
+
{
26
+
"cell_type": "markdown",
27
+
"metadata": {},
28
+
"source": [
29
+
"### Create some variables"
30
+
]
31
+
},
32
+
{
33
+
"cell_type": "code",
34
+
"collapsed": false,
35
+
"input": [
36
+
"a = 2\n",
37
+
"b = 1\n",
38
+
"c = 0\n",
39
+
"d = 3"
40
+
],
41
+
"language": "python",
42
+
"metadata": {},
43
+
"outputs": [],
44
+
"prompt_number": 41
45
+
},
46
+
{
47
+
"cell_type": "markdown",
48
+
"metadata": {},
49
+
"source": [
50
+
"### Assigns values from right side to left side"
51
+
]
52
+
},
53
+
{
54
+
"cell_type": "code",
55
+
"collapsed": false,
56
+
"input": [
57
+
"c = a + b\n",
58
+
"c"
59
+
],
60
+
"language": "python",
61
+
"metadata": {},
62
+
"outputs": [
63
+
{
64
+
"metadata": {},
65
+
"output_type": "pyout",
66
+
"prompt_number": 42,
67
+
"text": [
68
+
"3"
69
+
]
70
+
}
71
+
],
72
+
"prompt_number": 42
73
+
},
74
+
{
75
+
"cell_type": "markdown",
76
+
"metadata": {},
77
+
"source": [
78
+
"### Add right to the left and assign the result to left (c = a + c)"
79
+
]
80
+
},
81
+
{
82
+
"cell_type": "code",
83
+
"collapsed": false,
84
+
"input": [
85
+
"c += a\n",
86
+
"c"
87
+
],
88
+
"language": "python",
89
+
"metadata": {},
90
+
"outputs": [
91
+
{
92
+
"metadata": {},
93
+
"output_type": "pyout",
94
+
"prompt_number": 43,
95
+
"text": [
96
+
"5"
97
+
]
98
+
}
99
+
],
100
+
"prompt_number": 43
101
+
},
102
+
{
103
+
"cell_type": "markdown",
104
+
"metadata": {},
105
+
"source": [
106
+
"### Subtract right from the left and assign the result to left (c = a - c)"
107
+
]
108
+
},
109
+
{
110
+
"cell_type": "code",
111
+
"collapsed": false,
112
+
"input": [
113
+
"c -= a\n",
114
+
"c"
115
+
],
116
+
"language": "python",
117
+
"metadata": {},
118
+
"outputs": [
119
+
{
120
+
"metadata": {},
121
+
"output_type": "pyout",
122
+
"prompt_number": 44,
123
+
"text": [
124
+
"3"
125
+
]
126
+
}
127
+
],
128
+
"prompt_number": 44
129
+
},
130
+
{
131
+
"cell_type": "markdown",
132
+
"metadata": {},
133
+
"source": [
134
+
"### Multiply right with the left and assign the result to left (c = a * c)"
135
+
]
136
+
},
137
+
{
138
+
"cell_type": "code",
139
+
"collapsed": false,
140
+
"input": [
141
+
"c *= a\n",
142
+
"c"
143
+
],
144
+
"language": "python",
145
+
"metadata": {},
146
+
"outputs": [
147
+
{
148
+
"metadata": {},
149
+
"output_type": "pyout",
150
+
"prompt_number": 45,
151
+
"text": [
152
+
"6"
153
+
]
154
+
}
155
+
],
156
+
"prompt_number": 45
157
+
},
158
+
{
159
+
"cell_type": "markdown",
160
+
"metadata": {},
161
+
"source": [
162
+
"### Divide left with the right and assign the result to left (c = c / a)"
163
+
]
164
+
},
165
+
{
166
+
"cell_type": "code",
167
+
"collapsed": false,
168
+
"input": [
169
+
"c /= a\n",
170
+
"c"
171
+
],
172
+
"language": "python",
173
+
"metadata": {},
174
+
"outputs": [
175
+
{
176
+
"metadata": {},
177
+
"output_type": "pyout",
178
+
"prompt_number": 46,
179
+
"text": [
180
+
"3.0"
181
+
]
182
+
}
183
+
],
184
+
"prompt_number": 46
185
+
},
186
+
{
187
+
"cell_type": "markdown",
188
+
"metadata": {},
189
+
"source": [
190
+
"### Takes modulus using two operands and assign the result to left (a = d % a)"
191
+
]
192
+
},
193
+
{
194
+
"cell_type": "code",
195
+
"collapsed": false,
196
+
"input": [
197
+
"d %= a\n",
198
+
"d"
199
+
],
200
+
"language": "python",
201
+
"metadata": {},
202
+
"outputs": [
203
+
{
204
+
"metadata": {},
205
+
"output_type": "pyout",
206
+
"prompt_number": 47,
207
+
"text": [
208
+
"1"
209
+
]
210
+
}
211
+
],
212
+
"prompt_number": 47
213
+
},
214
+
{
215
+
"cell_type": "markdown",
216
+
"metadata": {},
217
+
"source": [
218
+
"### Exponential (power) calculation on operators and assign value to the left (d = d ^ a)"
219
+
]
220
+
},
221
+
{
222
+
"cell_type": "code",
223
+
"collapsed": false,
224
+
"input": [
225
+
"d **= a\n",
226
+
"d"
227
+
],
228
+
"language": "python",
229
+
"metadata": {},
230
+
"outputs": [
231
+
{
232
+
"metadata": {},
233
+
"output_type": "pyout",
234
+
"prompt_number": 48,
235
+
"text": [
236
+
"1"
237
+
]
238
+
}
239
+
],
240
+
"prompt_number": 48
241
+
},
242
+
{
243
+
"cell_type": "markdown",
244
+
"metadata": {},
245
+
"source": [
246
+
"### Floor division on operators and assign value to the left (d = d // a)"
0 commit comments