|
1 * Data Types |
|
2 *** Outline |
|
3 ***** Introduction |
|
4 ******* What are we going to do? |
|
5 ******* How are we going to do? |
|
6 ******* Arsenal Required |
|
7 ********* None |
|
8 *** Script |
|
9 Welcome friends. |
|
10 |
|
11 In this tutorial we shall look at data types available in Python and |
|
12 how to perform simple Input and Output operations. |
|
13 for 'Numbers' we have: int, float, complex datatypes |
|
14 for Text content we have strings. |
|
15 For conditional statements, 'Booleans'. |
|
16 |
|
17 Lets get started by opening IPython interpreter. |
|
18 Lets start with 'numbers' |
|
19 All integers irrespective of how big they are, are of 'int' |
|
20 data type |
|
21 Now we will create a variable, say |
|
22 x = 13 |
|
23 print x |
|
24 |
|
25 To check the data type of any variable Python provides 'type' function |
|
26 type(x) |
|
27 |
|
28 y = 999999999999 |
|
29 print y |
|
30 |
|
31 Floating point numbers comes under 'float' |
|
32 p = 3.141592 |
|
33 type(p) |
|
34 |
|
35 Python by default provides support for complex numbers. |
|
36 c = 3+4j |
|
37 c is a complex number. 'j' is used to specify the imaginary part. |
|
38 type(c) |
|
39 Python also provides basic functions for their manipulations like |
|
40 abs(c) will return the absolute value of c(sqrt(a^2 + b^2)) |
|
41 c.imag returns imaginary part and c.real gives the real part. |
|
42 |
|
43 Next we will look at Boolean datatype: |
|
44 Its a primitive datatype having one of two values: True or False. |
|
45 t = True |
|
46 print t |
|
47 |
|
48 Python is case sensitive language, so True with 'T' is boolean type but |
|
49 true with 't' would be a variable. |
|
50 |
|
51 f = not True |
|
52 |
|
53 we can do binary operation like 'or' and 'not' with these variables |
|
54 f or t |
|
55 f and t |
|
56 |
|
57 in case of multiple binary operations to make sure of precedence use |
|
58 'brackets ()' |
|
59 a = False |
|
60 b = True |
|
61 c = True |
|
62 (a and b) or c |
|
63 True |
|
64 first a and b is evaluated and then the 'or' statement |
|
65 a and (b or c) |
|
66 False |
|
67 |
|
68 we come to the end of this tutorial on introduction of Data types in |
|
69 Python. In this tutorial we have learnt what are supported data types, |
|
70 supported operations and performing simple IO operations in Python. |
|
71 |
|
72 *** Notes |