equal
deleted
inserted
replaced
26 {{{ Show the slide containing the outline slide }}} |
26 {{{ Show the slide containing the outline slide }}} |
27 |
27 |
28 In this tutorial, we shall look at |
28 In this tutorial, we shall look at |
29 |
29 |
30 * Datatypes in Python |
30 * Datatypes in Python |
31 * Operators in Python |
31 * Numbers |
|
32 * Boolean |
|
33 * Sequence |
|
34 * Operators in Python |
|
35 * Arithmetic Operators |
|
36 * Boolean Operators |
|
37 |
|
38 * Manipulating Sequence datatypes |
32 |
39 |
33 .. #[Puneeth: Use double colon only for code blocks.] |
40 .. #[Puneeth: Use double colon only for code blocks.] |
34 .. #[Puneeth: include more details in the outline.] |
41 .. #[Puneeth: include more details in the outline.] |
35 |
42 |
36 with a little hands-on on how they can be applied to the different data types. |
43 with a little hands-on on how they can be applied to the different data types. |
42 |
49 |
43 {{{ A slide to make a memory note of this }}} |
50 {{{ A slide to make a memory note of this }}} |
44 |
51 |
45 These are: |
52 These are: |
46 |
53 |
47 * int for integers |
54 * int |
48 * float for floating point numbers and |
55 * float |
49 * complex for complex numbers |
56 * complex |
50 |
57 |
51 .. #[Puneeth: Changed to int, float and complex.] |
58 .. #[Puneeth: Changed to int, float and complex.] |
52 |
59 |
53 .. #[Puneeth: Loss of consistency. You talk of built-in data types, but |
60 .. #[Puneeth: Loss of consistency. You talk of built-in data types, but |
54 .. then you were calling them integers, floats and complex. Clean up |
61 .. then you were calling them integers, floats and complex. Clean up |
55 .. required.] |
62 .. required.] |
56 |
63 |
57 Lets first talk about integers. :: |
64 Lets first talk about int. :: |
58 |
65 |
59 a = 13 |
66 a = 13 |
60 a |
67 a |
61 |
68 |
62 |
69 |
63 Now, we have our first integer variable a. |
70 Now, we have our first int variable a. |
64 |
71 |
65 |
72 |
66 If we now see :: |
73 If we now see :: |
67 |
74 |
68 type(a) |
75 type(a) |
76 |
83 |
77 .. #[Puneeth: Why are we suddenly talking of limits? |
84 .. #[Puneeth: Why are we suddenly talking of limits? |
78 .. Something like this would be better. |
85 .. Something like this would be better. |
79 .. int data-type can hold integers of any size. for example - ] |
86 .. int data-type can hold integers of any size. for example - ] |
80 |
87 |
81 Lets see the limits of this int. |
88 *int* datatype can hold integers of any size lets see this by example. |
82 |
89 |
83 b = 99999999999999999999 |
90 b = 99999999999999999999 |
84 b |
91 b |
85 |
92 |
86 As you can see even when we put a value of 9 repeated 20 times python did |
93 As you can see even when we put a value of 9 repeated 20 times python did |
91 type(b) |
98 type(b) |
92 <type 'long'> |
99 <type 'long'> |
93 |
100 |
94 |
101 |
95 The reason for this is that python recognizes large integer numbers by the |
102 The reason for this is that python recognizes large integer numbers by the |
96 data type long. However long type and integer type share there functions |
103 data type long. However long type and int type share there functions |
97 and properties. |
104 and properties. |
98 |
105 |
99 .. #[Puneeth: again, the clean-up that I talked of above. Decide if you are |
106 .. #[Puneeth: again, the clean-up that I talked of above. Decide if you are |
100 .. talking about the different type of numbers and the datatypes that are |
107 .. talking about the different type of numbers and the datatypes that are |
101 .. used to represent them or if you are talking of the data-types and what |
108 .. used to represent them or if you are talking of the data-types and what |
157 The results are self explanatory. |
164 The results are self explanatory. |
158 |
165 |
159 .. #[Puneeth: Why does booleans bring us to precedence? I don't see the |
166 .. #[Puneeth: Why does booleans bring us to precedence? I don't see the |
160 .. connection. Am I missing something?] |
167 .. connection. Am I missing something?] |
161 |
168 |
162 The usage of boolean brings us to an interesting question of precedence. |
169 |
163 What if you want to apply one operator before another. |
170 What if you want to apply one operator before another. |
164 |
171 |
165 Well you can use parenthesis for precedence. |
172 Well you can use parenthesis for precedence. |
166 |
173 |
167 Lets write some piece of code to check this out.:: |
174 Lets write some piece of code to check this out.:: |
168 |
175 |
169 In[]: a=False |
176 a=False |
170 In[]: b=True |
177 b=True |
171 In[]: c=True |
178 c=True |
172 |
179 |
173 |
180 |
174 .. #[Puneeth: Consistency. In[]: is not present at other places.] |
181 .. #[Puneeth: Consistency. In[]: is not present at other places.] |
175 |
182 |
176 To check how precedence changes with parenthesis, we will try two |
183 To check how precedence changes with parenthesis, we will try two |
193 these data types. |
200 these data types. |
194 |
201 |
195 .. #[Puneeth: A mention of other operators would be good? Starting |
202 .. #[Puneeth: A mention of other operators would be good? Starting |
196 .. with % and ** is a bit weird.] |
203 .. with % and ** is a bit weird.] |
197 |
204 |
198 Python uses % for modulo operation :: |
205 Python uses '+' for addition :: |
|
206 |
|
207 23 + 74 |
|
208 |
|
209 '-' for subtraction :: |
|
210 23 - 56 |
|
211 |
|
212 '*' for multiplication :: |
|
213 |
|
214 45*76 |
|
215 |
|
216 '/' for division :: |
|
217 |
|
218 384/16 |
|
219 |
|
220 '%' for modulo operation :: |
199 |
221 |
200 87 % 6 |
222 87 % 6 |
201 |
223 |
202 and two stars for a exponent. :: |
224 and two stars for a exponent. :: |
203 |
225 |
222 is same as :: |
244 is same as :: |
223 |
245 |
224 a=a/23 |
246 a=a/23 |
225 |
247 |
226 Lets now discuss sequence data types in Python. Sequence data types |
248 Lets now discuss sequence data types in Python. Sequence data types |
227 are those in which elements are kept in a sequential order. All the |
249 are those in which elements are kept in a sequential order and all the |
228 elements accessed using index. |
250 elements accessed using index numbers. |
229 |
251 |
230 .. #[Puneeth: fix the last sentence - it sounds incomplete] |
252 .. #[Puneeth: fix the last sentence - it sounds incomplete] |
231 |
253 |
232 {{{ slide for memory aid }}} |
254 {{{ slide for memory aid }}} |
233 |
255 |
255 var_list = [1, 1.2, [1,2]] |
277 var_list = [1, 1.2, [1,2]] |
256 var_list |
278 var_list |
257 |
279 |
258 .. #[Puneeth: some continuity, when jumping to strings?] |
280 .. #[Puneeth: some continuity, when jumping to strings?] |
259 |
281 |
260 Now we will have a look at strings |
282 Lets look at another sequence data type, strings |
261 |
283 |
262 type :: |
284 type :: |
263 |
285 |
264 greeting_string="hello" |
286 greeting_string="hello" |
265 |
287 |
269 {{{ Memory Aid Slide }}} |
291 {{{ Memory Aid Slide }}} |
270 |
292 |
271 Python strings can actually be defined in three different ways :: |
293 Python strings can actually be defined in three different ways :: |
272 |
294 |
273 k='Single quote' |
295 k='Single quote' |
274 l="Double quote contain's single quote" |
296 l="Let's see how to include a single quote" |
275 m='''"Contain's both"''' |
297 m='''"Let's see how to include both"''' |
276 |
298 |
277 .. #[Puneeth: Contain's? That's not a word!] |
299 .. #[Puneeth: Contain's? That's not a word!] |
278 |
300 |
279 Thus, single quotes are used as delimiters usually. |
301 As you can see, single quotes are used as delimiters usually. |
280 |
302 |
281 .. #[Puneeth: Thus?] |
303 .. #[Puneeth: Thus?] |
282 |
304 |
283 When a string contains a single quote, double quotes are used as |
305 When a string contains a single quote, double quotes are used as |
284 delimiters. When a string quote contains both single and double quotes, |
306 delimiters. When a string quote contains both single and double quotes, |
346 Get a sorted list and reversed list using sorted and reversed function :: |
368 Get a sorted list and reversed list using sorted and reversed function :: |
347 |
369 |
348 sorted(num_list) |
370 sorted(num_list) |
349 reversed(greeting_string) |
371 reversed(greeting_string) |
350 |
372 |
351 As a consequence of the order one we access a group of elements together. |
373 As a consequence of there order we can access a group of elements of sequence, |
352 This is called slicing and striding. |
374 together. This is called slicing and striding. |
353 |
375 |
354 .. #[Puneeth: Fix the sentence above. ] |
376 .. #[Puneeth: Fix the sentence above. ] |
355 |
377 |
356 First Slicing |
378 First Slicing |
357 |
379 |