Attachment 'terminal_1.txt'

Download

   1 odd% python
   2 Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
   3 [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
   4 Type "help", "copyright", "credits" or "license" for more information.
   5 >>> 1+1
   6 2
   7 >>> 3/2
   8 1
   9 >>> 3.0/2.0
  10 1.5
  11 >>> 3/2.0
  12 1.5
  13 >>> 3/2+1.0
  14 2.0
  15 >>> sin(1.0)
  16 Traceback (most recent call last):
  17   File "<stdin>", line 1, in <module>
  18 NameError: name 'sin' is not defined
  19 >>> from math import *
  20 >>> sin(1.0)
  21 0.8414709848078965
  22 >>> sqrt(-1)
  23 Traceback (most recent call last):
  24   File "<stdin>", line 1, in <module>
  25 ValueError: math domain error
  26 >>> from cmath import *
  27 >>> sqrt(-1)
  28 1j
  29 >>> a=5
  30 >>> a
  31 5
  32 >>> 5=y*3+1
  33   File "<stdin>", line 1
  34 SyntaxError: can't assign to literal
  35 >>> x=5
  36 >>> x*10
  37 50
  38 >>> x=3
  39 >>> x*10
  40 30
  41 >>> y=x*5+2
  42 >>> y
  43 17
  44 >>> x=7
  45 >>> y
  46 17
  47 >>> abcd=10
  48 >>> abcd
  49 10
  50 >>> a*b*c*d
  51 Traceback (most recent call last):
  52   File "<stdin>", line 1, in <module>
  53 NameError: name 'b' is not defined
  54 >>> a=1
  55 >>> b=2.0
  56 >>> a
  57 1
  58 >>> b
  59 2.0
  60 >>> 1==1
  61 True
  62 >>> 1==2
  63 False
  64 >>> a=1
  65 >>> b=1.0
  66 >>> a==b
  67 True
  68 >>> "alphabet"
  69 'alphabet'
  70 >>> 'alphabet'
  71 'alphabet'
  72 >>> "you can't do that"
  73 "you can't do that"
  74 >>> 'you can't do that'
  75   File "<stdin>", line 1
  76     'you can't do that'
  77              ^
  78 SyntaxError: invalid syntax
  79 >>> """this is a string"""
  80 'this is a string'
  81 >>> """this is a string
  82 ... it has more than
  83 ... one line"""
  84 'this is a string\nit has more than\none line'
  85 >>> print """this is a string
  86 ... that spans several
  87 ... lines"""
  88 this is a string
  89 that spans several
  90 lines
  91 >>> a="this is a test"
  92 >>> a
  93 'this is a test'
  94 >>> b=" more string"
  95 >>> a
  96 'this is a test'
  97 >>> b
  98 ' more string'
  99 >>> a+b
 100 'this is a test more string'
 101 >>> b*3
 102 ' more string more string more string'
 103 >>> a="10"
 104 >>> a*3
 105 '101010'
 106 >>> int(a)
 107 10
 108 >>> a
 109 '10'
 110 >>> int(a)*3
 111 30
 112 >>> string(255)
 113 Traceback (most recent call last):
 114   File "<stdin>", line 1, in <module>
 115 NameError: name 'string' is not defined
 116 >>> str(255)
 117 '255'
 118 >>> float(a)
 119 10.0
 120 >>> a
 121 '10'
 122 >>> [1,23,5,7]
 123 [1, 23, 5, 7]
 124 >>> a=[1,23,5,7]
 125 >>> a
 126 [1, 23, 5, 7]
 127 >>> a*2
 128 [1, 23, 5, 7, 1, 23, 5, 7]
 129 >>> a[0]
 130 1
 131 >>> a[1]
 132 23
 133 >>> a[2]
 134 5
 135 >>> a=[1,2,"alpha",2.5]
 136 >>> a
 137 [1, 2, 'alpha', 2.5]
 138 >>> a=[1,2,[1,2,3],7]
 139 >>> a
 140 [1, 2, [1, 2, 3], 7]
 141 >>> a[0]
 142 1
 143 >>> a[2]
 144 [1, 2, 3]
 145 >>> a[2][1]
 146 2
 147 >>> a[1,2,3,5,6,8,9,100]
 148 Traceback (most recent call last):
 149   File "<stdin>", line 1, in <module>
 150 TypeError: list indices must be integers, not tuple
 151 >>> a=[1,2,3,5,6,8,9,100]
 152 >>> a
 153 [1, 2, 3, 5, 6, 8, 9, 100]
 154 >>> a[0:3]
 155 [1, 2, 3]
 156 >>> a[0:3]+a[3:5]
 157 [1, 2, 3, 5, 6]
 158 >>> a[-1]
 159 100
 160 >>> a[-2]
 161 9
 162 >>> a[:3]
 163 [1, 2, 3]
 164 >>> a[5:]
 165 [8, 9, 100]
 166 >>> a[-3:]
 167 [8, 9, 100]
 168 >>> a[:]
 169 [1, 2, 3, 5, 6, 8, 9, 100]
 170 >>> a
 171 [1, 2, 3, 5, 6, 8, 9, 100]
 172 >>> a[1]=55
 173 >>> a
 174 [1, 55, 3, 5, 6, 8, 9, 100]
 175 >>> b=a
 176 >>> b
 177 [1, 55, 3, 5, 6, 8, 9, 100]
 178 >>> a[1]=7
 179 >>> a
 180 [1, 7, 3, 5, 6, 8, 9, 100]
 181 >>> b
 182 [1, 7, 3, 5, 6, 8, 9, 100]
 183 >>> c=7
 184 >>> d=8
 185 >>> c=5
 186 >>> d
 187 8
 188 >>> c=7
 189 >>> d=c
 190 >>> =5
 191   File "<stdin>", line 1
 192     =5
 193     ^
 194 SyntaxError: invalid syntax
 195 >>> c=5
 196 >>> d
 197 7
 198 >>> a
 199 [1, 7, 3, 5, 6, 8, 9, 100]
 200 >>> b
 201 [1, 7, 3, 5, 6, 8, 9, 100]
 202 >>> b=a[:]
 203 >>> b
 204 [1, 7, 3, 5, 6, 8, 9, 100]
 205 >>> a[1]=10
 206 >>> a
 207 [1, 10, 3, 5, 6, 8, 9, 100]
 208 >>> b
 209 [1, 7, 3, 5, 6, 8, 9, 100]
 210 >>> a=0
 211 >>> b=0
 212 >>> a
 213 0
 214 >>> b
 215 0
 216 >>> a="this is a test"
 217 >>> a[0]
 218 't'
 219 >>> a[3:7]
 220 's is'
 221 >>> a[0]="x"
 222 Traceback (most recent call last):
 223   File "<stdin>", line 1, in <module>
 224 TypeError: 'str' object does not support item assignment
 225 >>> a
 226 'this is a test'
 227 >>> a="x"+a[1:]
 228 >>> a
 229 'xhis is a test'
 230 >>> a=(1,2,3,6,8,9)
 231 >>> a
 232 (1, 2, 3, 6, 8, 9)
 233 >>> a[0]=5
 234 Traceback (most recent call last):
 235   File "<stdin>", line 1, in <module>
 236 TypeError: 'tuple' object does not support item assignment
 237 >>> set((1,2,3,4,5))
 238 set([1, 2, 3, 4, 5])
 239 >>> set((1,2,2,5,3,4,5))
 240 set([1, 2, 3, 4, 5])
 241 >>> set((5,2,3,1))
 242 set([1, 2, 3, 5])
 243 >>> a={1:2,2:3,3:4,4:5}
 244 >>> a
 245 {1: 2, 2: 3, 3: 4, 4: 5}
 246 >>> a[1]
 247 2
 248 >>> a[3]
 249 4
 250 >>> a[8]
 251 Traceback (most recent call last):
 252   File "<stdin>", line 1, in <module>
 253 KeyError: 8
 254 >>> a={"a":5,"b":7,3:10,"c":"alpha"}
 255 >>> 
 256 >>> a
 257 {'a': 5, 3: 10, 'c': 'alpha', 'b': 7}
 258 >>> a["a"]
 259 5
 260 >>> a[3]
 261 10
 262 >>> a["c"]
 263 'alpha'
 264 >>> a["xxx"]
 265 Traceback (most recent call last):
 266   File "<stdin>", line 1, in <module>
 267 KeyError: 'xxx'
 268 >>> a
 269 {'a': 5, 3: 10, 'c': 'alpha', 'b': 7}
 270 >>> a[22]="abcd"
 271 >>> a
 272 {'a': 5, 3: 10, 'c': 'alpha', 'b': 7, 22: 'abcd'}
 273 >>> a[22]=15
 274 >>> a
 275 {'a': 5, 3: 10, 'c': 'alpha', 'b': 7, 22: 15}
 276 >>> ^D
 277 odd% 

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.