Attachment 'terminal_2.txt'

Download

   1 Last login: Sun Jan  5 11:39:54 on ttys002
   2 odd% ipython
   3 Leopard libedit detected.
   4 Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
   5 Type "copyright", "credits" or "license" for more information.
   6 
   7 IPython 0.10 -- An enhanced Interactive Python.
   8 ?         -> Introduction and overview of IPython's features.
   9 %quickref -> Quick reference.
  10 help      -> Python's own help system.
  11 object?   -> Details about 'object'. ?object also works, ?? prints more.
  12 
  13 In [1]: len("abcdef")
  14 Out[1]: 6
  15 
  16 In [2]: len([1,2,3,4])
  17 Out[2]: 4
  18 
  19 In [3]: len(set([1,3,5]))
  20 Out[3]: 3
  21 
  22 In [4]: a=[1,2,4,6,7]
  23 
  24 In [5]: tuple(a)
  25 Out[5]: (1, 2, 4, 6, 7)
  26 
  27 In [6]: str(a)
  28 Out[6]: '[1, 2, 4, 6, 7]'
  29 
  30 In [7]: list(str(a))
  31 Out[7]: ['[', '1', ',', ' ', '2', ',', ' ', '4', ',', ' ', '6', ',', ' ', '7', ']']
  32 
  33 In [8]: set("alphabet soup")
  34 Out[8]: set([' ', 'a', 'b', 'e', 'h', 'l', 'o', 'p', 's', 't', 'u'])
  35 
  36 In [9]: range(5)
  37 Out[9]: [0, 1, 2, 3, 4]
  38 
  39 In [10]: range(2,5)
  40 Out[10]: [2, 3, 4]
  41 
  42 In [11]: range(2,20,2)
  43 Out[11]: [2, 4, 6, 8, 10, 12, 14, 16, 18]
  44 
  45 In [12]: xrange(2,20,2)
  46 Out[12]: xrange(2, 20, 2)
  47 
  48 In [13]: xrange(100000000)
  49 KeyboardInterrupt
  50 
  51 In [13]: raw_input()
  52 hi there 
  53 Out[13]: 'hi there '
  54 
  55 In [14]: a=raw_input()
  56 this is a test
  57 
  58 In [15]: a
  59 Out[15]: 'this is a test'
  60 
  61 In [16]: a=raw_input()
  62 10
  63 
  64 In [17]: a
  65 Out[17]: '10'
  66 
  67 In [18]: input()
  68 10
  69 Out[18]: 10
  70 
  71 In [19]: 10
  72 Out[19]: 10
  73 
  74 In [20]: input()
  75 10+10*100
  76 Out[20]: 1010
  77 
  78 In [21]: max([1,3,2,5,9,7])
  79 Out[21]: 9
  80 
  81 In [22]: min([1,3,2,5,9,7])
  82 Out[22]: 1
  83 
  84 In [23]: max("alphabet")
  85 Out[23]: 't'
  86 
  87 In [24]: a=(1,3,7,6,5,2)
  88 
  89 In [25]: a
  90 Out[25]: (1, 3, 7, 6, 5, 2)
  91 
  92 In [26]: b=list(a)
  93 
  94 In [27]: b
  95 Out[27]: [1, 3, 7, 6, 5, 2]
  96 
  97 In [28]: b.sort()
  98 
  99 In [29]: b
 100 Out[29]: [1, 2, 3, 5, 6, 7]
 101 
 102 In [30]: a.sort()
 103 ---------------------------------------------------------------------------
 104 AttributeError                            Traceback (most recent call last)
 105 
 106 /Users/stevel/<ipython console> in <module>()
 107 
 108 AttributeError: 'tuple' object has no attribute 'sort'
 109 
 110 In [31]: sorted(a)
 111 Out[31]: [1, 2, 3, 5, 6, 7]
 112 
 113 In [32]: reversed(sorted(a))
 114 Out[32]: <listreverseiterator object at 0x1056dc6d0>
 115 
 116 In [33]: list(reversed(sorted(a)))
 117 Out[33]: [7, 6, 5, 3, 2, 1]
 118 
 119 In [34]: print "this is a test"
 120 -------> print("this is a test")
 121 this is a test
 122 
 123 In [35]: print "this is a test",1,3,5,a
 124 -------> print("this is a test",1,3,5,a)
 125 ('this is a test', 1, 3, 5, (1, 3, 7, 6, 5, 2))
 126 
 127 In [36]: print "this is a test",1,3,5,a
 128 -------> print("this is a test",1,3,5,a)
 129 ('this is a test', 1, 3, 5, (1, 3, 7, 6, 5, 2))
 130 
 131 In [37]: ^D
 132 Do you really want to exit ([y]/n)? 
 133 odd% python
 134 Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
 135 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
 136 Type "help", "copyright", "credits" or "license" for more information.
 137 >>> print "this is a test",1,3,5
 138 this is a test 1 3 5
 139 >>> a="this is a test"
 140 >>> a.upper()
 141 'THIS IS A TEST'
 142 >>> a.lower()
 143 'this is a test'
 144 >>> a.title()
 145 'This Is A Test'
 146 >>> a="this is a test 1 2 3"
 147 >>> a.title()
 148 'This Is A Test 1 2 3'
 149 >>> a
 150 'this is a test 1 2 3'
 151 >>> a.count("t")
 152 3
 153 >>> a.count("is")
 154 2
 155 >>> a.find("is")
 156 2
 157 >>> a[2]
 158 'i'
 159 >>> a[2:3]
 160 'i'
 161 >>> a[2:4]
 162 'is'
 163 >>> a.rfind("is")
 164 5
 165 >>> a.replace("is","was")
 166 'thwas was a test 1 2 3'
 167 >>> a.replace("is","")
 168 'th  a test 1 2 3'
 169 >>> a=str([1,3,5,7,9])
 170 >>> a
 171 '[1, 3, 5, 7, 9]'
 172 >>> a.split(",")
 173 ['[1', ' 3', ' 5', ' 7', ' 9]']
 174 >>> a[1:-1].split(",")
 175 ['1', ' 3', ' 5', ' 7', ' 9']
 176 >>> a="""this is
 177 ... a multiline
 178 ...     test
 179 ... 
 180 ... """
 181 >>> a
 182 'this is\na multiline\n    test\n\n'
 183 >>> print a
 184 this is
 185 a multiline
 186     test
 187 
 188 
 189 >>> a.split()
 190 ['this', 'is', 'a', 'multiline', 'test']
 191 >>> a.split(" ")
 192 ['this', 'is\na', 'multiline\n', '', '', '', 'test\n\n']
 193 >>> a.split()
 194 ['this', 'is', 'a', 'multiline', 'test']
 195 >>> b=a[1:-1].split(",")
 196 >>> b
 197 ['his is\na multiline\n    test\n']
 198 >>> a=str([1,3,5,7,9])
 199 >>> b
 200 ['his is\na multiline\n    test\n']
 201 >>> b=a[1:-1].split(",")
 202 >>> b
 203 ['1', ' 3', ' 5', ' 7', ' 9']
 204 >>> print b
 205 ['1', ' 3', ' 5', ' 7', ' 9']
 206 >>> print ",".join(b)
 207 1, 3, 5, 7, 9
 208 >>> print ".".join(b)
 209 1. 3. 5. 7. 9
 210 >>> "is" in "this is a test"
 211 True
 212 >>> "if" in "this is a test"
 213 False
 214 >>> "this is a test".find("xxxx")
 215 -1
 216 >>> a=range(10)
 217 >>> a
 218 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 219 >>> a.append("bbb")
 220 >>> a
 221 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'bbb']
 222 >>> a=range(5)
 223 >>> b=range(8)
 224 >>> a
 225 [0, 1, 2, 3, 4]
 226 >>> b
 227 [0, 1, 2, 3, 4, 5, 6, 7]
 228 >>> a+b
 229 [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7]
 230 >>> a.extend(b)
 231 >>> a
 232 [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7]
 233 >>> b
 234 [0, 1, 2, 3, 4, 5, 6, 7]
 235 >>> a
 236 [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7]
 237 >>> del a[7]
 238 >>> a
 239 [0, 1, 2, 3, 4, 0, 1, 3, 4, 5, 6, 7]
 240 >>> a.remove(1)
 241 >>> a
 242 [0, 2, 3, 4, 0, 1, 3, 4, 5, 6, 7]
 243 >>> a.remove(1)
 244 >>> a
 245 [0, 2, 3, 4, 0, 3, 4, 5, 6, 7]
 246 >>> a.remove(1)
 247 Traceback (most recent call last):
 248   File "<stdin>", line 1, in <module>
 249 ValueError: list.remove(x): x not in list
 250 >>> a
 251 [0, 2, 3, 4, 0, 3, 4, 5, 6, 7]
 252 >>> a.index[6]
 253 Traceback (most recent call last):
 254   File "<stdin>", line 1, in <module>
 255 TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
 256 >>> a.index(6)
 257 8
 258 >>> del a[a.index(6)]
 259 KeyboardInterrupt
 260 >>> a.remove(6)
 261 KeyboardInterrupt
 262 >>> a={1:2,2:3,"a":"x"}
 263 >>> a
 264 {'a': 'x', 1: 2, 2: 3}
 265 >>> a[1]
 266 2
 267 >>> a.keys()
 268 ['a', 1, 2]
 269 >>> a.values()
 270 ['x', 2, 3]
 271 >>> a.items()
 272 [('a', 'x'), (1, 2), (2, 3)]
 273 >>> a.items()[2]
 274 (2, 3)
 275 >>> a.items()[2][0]
 276 2
 277 >>> a.items()[2][1]
 278 3
 279 >>> a.has_key(5)
 280 False
 281 >>> a.has_key(1)
 282 True
 283 >>> 1 in a.keys()
 284 True
 285 >>> a["x"]=10
 286 >>> a
 287 {'a': 'x', 1: 2, 2: 3, 'x': 10}
 288 >>> a[4]=0
 289 >>> a[4]=a[4]+1
 290 >>> a[4]=a[4]+1
 291 >>> a[4]=a[4]+1
 292 >>> a[4]
 293 3
 294 >>> a[4]=a[4]+1
 295 >>> a[4]=a[4]+1
 296 >>> a[4]
 297 5
 298 >>> a.set_default(5,0)
 299 Traceback (most recent call last):
 300   File "<stdin>", line 1, in <module>
 301 AttributeError: 'dict' object has no attribute 'set_default'
 302 >>> a.get_default(5,0)
 303 Traceback (most recent call last):
 304   File "<stdin>", line 1, in <module>
 305 AttributeError: 'dict' object has no attribute 'get_default'
 306 >>> a.setdefault(5,0)
 307 0
 308 >>> a
 309 {'a': 'x', 1: 2, 2: 3, 4: 5, 5: 0, 'x': 10}
 310 >>> a[5]=a[5]+1
 311 >>> a
 312 {'a': 'x', 1: 2, 2: 3, 4: 5, 5: 1, 'x': 10}
 313 >>> a[5]
 314 1
 315 >>> a.setdefault(5,0)
 316 1
 317 >>> a=set((1,3,5,7,9))
 318 >>> b=set((1,4,6,7,10))
 319 >>> a
 320 set([1, 3, 9, 5, 7])
 321 >>> b
 322 set([1, 10, 4, 6, 7])
 323 >>> a.union(b)
 324 set([1, 3, 4, 5, 6, 7, 9, 10])
 325 >>> b.union(a)
 326 set([1, 3, 4, 5, 6, 7, 9, 10])
 327 >>> a.intersection(b)
 328 set([1, 7])
 329 >>> a.difference(b)
 330 set([9, 3, 5])
 331 >>> b.difference(a)
 332 set([10, 4, 6])
 333 >>> a
 334 set([1, 3, 9, 5, 7])
 335 >>> a.remove(9)
 336 >>> a
 337 set([1, 3, 5, 7])
 338 >>> a.remove(9)
 339 Traceback (most recent call last):
 340   File "<stdin>", line 1, in <module>
 341 KeyError: 9
 342 >>> a.discard(5)
 343 >>> a
 344 set([1, 3, 7])
 345 >>> a.discard(5)
 346 >>> ^D
 347 odd% 
 348 odd% vi x.py
 349 odd% vi y.py
 350 odd% cat y.py
 351 import math
 352 
 353 print math.sin(10.0),math.sin(20.0)
 354 odd% python y.py
 355 -0.544021110889 0.912945250728
 356 odd% vi y.py 
 357 odd% python
 358 Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
 359 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
 360 Type "help", "copyright", "credits" or "license" for more information.
 361 >>> import math
 362 >>> 
 363 >>> math.sin(10.0)
 364 -0.5440211108893699
 365 >>> math.sin(20.0)
 366 0.9129452507276277
 367 >>> ^D
 368 odd% python y.py
 369 odd% 
 370 odd% !vi
 371 vi y.py
 372 odd% python y.py
 373 -0.544021110889
 374 0.912945250728
 375 odd% y.py
 376 zsh: permission denied: y.py
 377 odd% vi y.py
 378 odd% y.py   
 379 zsh: permission denied: y.py
 380 odd% chmod a+x y.py
 381 odd% y.py
 382 -0.544021110889
 383 0.912945250728
 384 odd% idle
 385 odd% cat z.py
 386 from math import *
 387 
 388 print sin(10.0)
 389 
 390 print cos(20.0)
 391 odd% a=[1,2,3,4,5]
 392 odd% python
 393 Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
 394 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
 395 Type "help", "copyright", "credits" or "license" for more information.
 396 >>> a=[1,2,3,4,5]
 397 >>> for i in a:
 398 ...  print i,i*2
 399 ... 
 400 1 2
 401 2 4
 402 3 6
 403 4 8
 404 5 10
 405 >>> ^D
 406 odd% idle

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.