Chapter 6: Data Types Revisted

char Example, Page number: 218

In [4]:
#Variable declaration
ch = 291

#Result
print "%d %c" %( ch, (ch%128) ) 
291 #

Range of char, Page number: 218

In [5]:
for ch in range(0,256):
    print  "%d %c" %(ch, ch%128 )
0 
1 
2 
3 
4 
5 
6 
7 
8 
9 	
10 

11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32  
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
42 *
43 +
44 ,
45 -
46 .
47 /
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
64 @
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
120 x
121 y
122 z
123 {
124 |
125 }
126 ~
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 	
138 

139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 
159 
160  
161 !
162 "
163 #
164 $
165 %
166 &
167 '
168 (
169 )
170 *
171 +
172 ,
173 -
174 .
175 /
176 0
177 1
178 2
179 3
180 4
181 5
182 6
183 7
184 8
185 9
186 :
187 ;
188 <
189 =
190 >
191 ?
192 @
193 A
194 B
195 C
196 D
197 E
198 F
199 G
200 H
201 I
202 J
203 K
204 L
205 M
206 N
207 O
208 P
209 Q
210 R
211 S
212 T
213 U
214 V
215 W
216 X
217 Y
218 Z
219 [
220 \
221 ]
222 ^
223 _
224 `
225 a
226 b
227 c
228 d
229 e
230 f
231 g
232 h
233 i
234 j
235 k
236 l
237 m
238 n
239 o
240 p
241 q
242 r
243 s
244 t
245 u
246 v
247 w
248 x
249 y
250 z
251 {
252 |
253 }
254 ~
255 

Scope and Life of Automatic Variable, Page number: 225

In [8]:
#Variable declaration
i = 1 #auto int

def b2 (i):
    print i 

def b3 (i):
    print i 


def b1 (i):
    print  i 
    b2(i)
    b3(i)


#Result
b1(i)
1
1
1

Scope and Life of Automatic Variable, Page number: 226

In [9]:
#Variable declaration
i = 1 #auto int

def b2 (i):
    i = 2 # auto int  
    print i 

def b3 (i):
    i = 3 #auto int 
    print i 


def b1 (i):
    b3(i)
    b2(i)
    print  i 


#Result
b1(i)
3
2
1

Different Data Types, Page number: 220

In [3]:
c = 'a'
d = 'b'
print "%c %c" %( c, d )

i = 333
j = 288
print "%d %u"%( i, j ) 


k = 2
l = 1
print "%d %u " %(k, l ) 

m = 73277727727
n = 189189819891
print  "%ld %lu"%( m, n ) 


#float, double, long double
from decimal import Decimal    
#x,y,z = raw_input ( "float double long double: ").split()
x = 72.12
y = Decimal(8282910.0109010)
z = Decimal(29189999111.128918918)
print  x, y, z 
a b
333 288
2 1 
73277727727 189189819891
72.12 8282910.0109010003507137298583984375 29189999111.128917694091796875

Auto Increment, Page number: 228

In [6]:
#function definition 
def increment( ):
    i = 1 #auto int
    print i 
    i = i + 1 

#function calls
increment( )
increment( )
increment( )
1
1
1

Static Increment, Page number: 228

In [7]:
#function definition 
def increment(i = [1]): #static int 
    print i[0] 
    i[0] += 1 

#function calls
increment()
increment()
increment()
1
2
3

Static Storage Class, Page number: 229

In [3]:
#function definition
def fun( ):
    k = 35 
    return (k)

j = fun( ) #function call
print j  #result
35

External Storage Class, Page number: 231

In [10]:
#Variable declaration 
i = [0] # external variable

#Function definitions 
def increment(i = [0]):
    i[0] += 1
    print  "on incrementing i = ", i[0]  


def decrement(i = [2]):
    i[0] -= 1
    print  "on decrementing i = ", i[0] 
    


print  "i = ", i[0]
#function calls
increment() 
increment() 
decrement() 
decrement() 
i =  0
on incrementing i =  1
on incrementing i =  2
on decrementing i =  1
on decrementing i =  0
In [ ]: