barty @ python3
Python 3.2.3 (default, Sep 10 2012, 12:58:42)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 5
>>> x
5
>>> x = "hello"
>>> x = 5 + 3.2
>>> x
8.2
>>> int("3")
3
>>> from math import *
>>> sqrt(2)
1.4142135623730951
>>> sin(pi/2)
1.0
>>> z + 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'z' is not defined
>>> 3 + "hello"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> b = Ture
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Ture' is not defined
>>> b = True or False
>>> b
True
>>> if b:
... print("yep")
...
yep
>>> b = 1 or 2
>>> b
1
>>> b = bool(1)
>>> b
True
>>> bool(0)
False
>>> bool("")
False
>>> bool("x")
True
>>> bool("xy")
True
>>> bool("xzzy")
True
>>> bool(" ")
True
>>> "xx" + "yy"
'xxyy'
>>> "hello" + " " + "world"
'hello world'
>>> x = "hello" + " " + "world"
>>> x
'hello world'
>>> sqrt("x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a float is required
>>> sqrt(2)
1.4142135623730951
>>> print("x")
x
>>> print(5)
5
>>> from math import *
>>> print("x")
x
>>> print(5)
5
>>> print(5, " = x")
5 = x
>>> print(5, "= x")
5 = x
>>> print(5, "= x", end="*")
5 = x*>>>
>>>
>>>
>>> "hello" * 3
'hellohellohello'
>>> from math import *
>>> import math
>>> math.sqrt(3)
1.7320508075688772
>>>
>>>
>>> "hello" * 3
'hellohellohello'
>>>
>>>
>>> "hello"[0]
'h'
>>> "hello"[1]
'e'
>>> "hello"[3]
'l'
>>> "hello"[4]
'o'
>>> "hello"[4][0]
'o'
>>> "hello"[4][1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> True[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bool' object is not subscriptable
>>> "hello"[0] = 'j'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>>
>>> "hello"[-1]
'o'
>>> len("hello")
5
>>> "hello"[len("hello")-1]
'o'
>>> len("hello")
5
>>> len("hello" - 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>> len("hello" - 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>> len("hello") - 1
4
>>> "hello"[len("hello") - 1]
'o'
>>> x = "scrumpdillyishus"
>>> x[len(x) - 1]
's'
>>> x[-1]
's'
>>>
>>>
>>>
>>>
>>> "hello"[4]
'o'
>>> 'o'[0]
'o'
>>> "hello"[4][0]
'o'
>>>
>>> "hello"[1:3]
'el'
>>> "hello"[0:5]
'hello'
>>> "hello"[0:]
'hello'
>>> "hello"[:]
'hello'
>>> "hello"[:3]
'hel'
>>> "hello"[1:]
'ello'
>>>
>>> 'j' + "hello"[1:]
'jello'
>>> 'hello'[3]
'l'
>>>
>>>
>>>
barty @ python3
Python 3.2.3 (default, Sep 10 2012, 12:58:42)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "\n"
'\n'
>>> print("
File "<stdin>", line 1
print("
^
SyntaxError: EOL while scanning string literal
>>> print("\n")
>>> print("\n", end="")
>>> print("\thello\tworld", end="")
hello world>>> print("\thello\tworld"\)
File "<stdin>", line 1
print("\thello\tworld"\)
^
SyntaxError: unexpected character after line continuation character
>>> print("\thello\tworld"\)
File "<stdin>", line 1
print("\thello\tworld"\)
^
SyntaxError: unexpected character after line continuation character
>>> print("\thello\tworld")
hello world
>>>
>>>
>>> [1, 2, 3]
[1, 2, 3]
>>> [1, 2, 3][0]
1
>>> [1, 2, 3][0:2]
[1, 2]
>>> [1, "a", "bc", False]
[1, 'a', 'bc', False]
>>> [3, [1, "a", "bc", False]]
[3, [1, 'a', 'bc', False]]
>>> [3, [1, "a", "bc", False]][1][0]
1
>>> x = [3, [1, "a", "bc", False]][1][0]
>>> x[0][0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not subscriptable
>>>
>>> x[0] = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item assignment
>>> x
1
>>> x = [3, [1, "a", "bc", False]][1][0]
>>> x[0] = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item assignment
>>> x = [3, [1, "a", "bc", False]]
>>>
>>>
>>> x[0] = 5
>>> x
[5, [1, 'a', 'bc', False]]
>>>
>>>
>>> print([0,1,2])
[0, 1, 2]
>>> str([0,1,2])
'[0, 1, 2]'
>>> x = [3, [1, "a", "bc", False]]
>>> len(x)
2
>>> range(1,5)
range(1, 5)
>>> range(1, 5)
range(1, 5)
>>> range(5)
range(0, 5)
>>> x=range(1,5)
>>> x
range(1, 5)
>>> for i in range(1,5):
... print(i)
...
1
2
3
4
>>> for i in "hello":
... print(i)
...
h
e
l
l
o
>>> n = int(input("maximum "))
maximum 5
>>> for i in range(n):
... print(i)
...
0
1
2
3
4
>>> for i in range(1,n,2):
... print(i)
...
1
3
>>>
KeyboardInterrupt
>>>
barty @ more dotify3.py
# Copyright (c) 2013 Bart Massey
# Put dots between characters in a string
s = input("string to dotify? ")
dot_s = s[0]
for c in s[1:]:
dot_s = dot_s + '.' + c
print(dot_s)
barty @ emacs dotify3.py
barty @ python3
Python 3.2.3 (default, Sep 10 2012, 12:58:42)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> (1, 2)
(1, 2)
>>> (1, 2) + (3, 4)
(1, 2, 3, 4)
>>> (1, 2)[0] = 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>>
Python 3.2.3 (default, Sep 10 2012, 12:58:42)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 5
>>> x
5
>>> x = "hello"
>>> x = 5 + 3.2
>>> x
8.2
>>> int("3")
3
>>> from math import *
>>> sqrt(2)
1.4142135623730951
>>> sin(pi/2)
1.0
>>> z + 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'z' is not defined
>>> 3 + "hello"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
>>> b = Ture
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Ture' is not defined
>>> b = True or False
>>> b
True
>>> if b:
... print("yep")
...
yep
>>> b = 1 or 2
>>> b
1
>>> b = bool(1)
>>> b
True
>>> bool(0)
False
>>> bool("")
False
>>> bool("x")
True
>>> bool("xy")
True
>>> bool("xzzy")
True
>>> bool(" ")
True
>>> "xx" + "yy"
'xxyy'
>>> "hello" + " " + "world"
'hello world'
>>> x = "hello" + " " + "world"
>>> x
'hello world'
>>> sqrt("x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a float is required
>>> sqrt(2)
1.4142135623730951
>>> print("x")
x
>>> print(5)
5
>>> from math import *
>>> print("x")
x
>>> print(5)
5
>>> print(5, " = x")
5 = x
>>> print(5, "= x")
5 = x
>>> print(5, "= x", end="*")
5 = x*>>>
>>>
>>>
>>> "hello" * 3
'hellohellohello'
>>> from math import *
>>> import math
>>> math.sqrt(3)
1.7320508075688772
>>>
>>>
>>> "hello" * 3
'hellohellohello'
>>>
>>>
>>> "hello"[0]
'h'
>>> "hello"[1]
'e'
>>> "hello"[3]
'l'
>>> "hello"[4]
'o'
>>> "hello"[4][0]
'o'
>>> "hello"[4][1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> True[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bool' object is not subscriptable
>>> "hello"[0] = 'j'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>>
>>> "hello"[-1]
'o'
>>> len("hello")
5
>>> "hello"[len("hello")-1]
'o'
>>> len("hello")
5
>>> len("hello" - 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>> len("hello" - 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>> len("hello") - 1
4
>>> "hello"[len("hello") - 1]
'o'
>>> x = "scrumpdillyishus"
>>> x[len(x) - 1]
's'
>>> x[-1]
's'
>>>
>>>
>>>
>>>
>>> "hello"[4]
'o'
>>> 'o'[0]
'o'
>>> "hello"[4][0]
'o'
>>>
>>> "hello"[1:3]
'el'
>>> "hello"[0:5]
'hello'
>>> "hello"[0:]
'hello'
>>> "hello"[:]
'hello'
>>> "hello"[:3]
'hel'
>>> "hello"[1:]
'ello'
>>>
>>> 'j' + "hello"[1:]
'jello'
>>> 'hello'[3]
'l'
>>>
>>>
>>>
barty @ python3
Python 3.2.3 (default, Sep 10 2012, 12:58:42)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "\n"
'\n'
>>> print("
File "<stdin>", line 1
print("
^
SyntaxError: EOL while scanning string literal
>>> print("\n")
>>> print("\n", end="")
>>> print("\thello\tworld", end="")
hello world>>> print("\thello\tworld"\)
File "<stdin>", line 1
print("\thello\tworld"\)
^
SyntaxError: unexpected character after line continuation character
>>> print("\thello\tworld"\)
File "<stdin>", line 1
print("\thello\tworld"\)
^
SyntaxError: unexpected character after line continuation character
>>> print("\thello\tworld")
hello world
>>>
>>>
>>> [1, 2, 3]
[1, 2, 3]
>>> [1, 2, 3][0]
1
>>> [1, 2, 3][0:2]
[1, 2]
>>> [1, "a", "bc", False]
[1, 'a', 'bc', False]
>>> [3, [1, "a", "bc", False]]
[3, [1, 'a', 'bc', False]]
>>> [3, [1, "a", "bc", False]][1][0]
1
>>> x = [3, [1, "a", "bc", False]][1][0]
>>> x[0][0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not subscriptable
>>>
>>> x[0] = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item assignment
>>> x
1
>>> x = [3, [1, "a", "bc", False]][1][0]
>>> x[0] = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object does not support item assignment
>>> x = [3, [1, "a", "bc", False]]
>>>
>>>
>>> x[0] = 5
>>> x
[5, [1, 'a', 'bc', False]]
>>>
>>>
>>> print([0,1,2])
[0, 1, 2]
>>> str([0,1,2])
'[0, 1, 2]'
>>> x = [3, [1, "a", "bc", False]]
>>> len(x)
2
>>> range(1,5)
range(1, 5)
>>> range(1, 5)
range(1, 5)
>>> range(5)
range(0, 5)
>>> x=range(1,5)
>>> x
range(1, 5)
>>> for i in range(1,5):
... print(i)
...
1
2
3
4
>>> for i in "hello":
... print(i)
...
h
e
l
l
o
>>> n = int(input("maximum "))
maximum 5
>>> for i in range(n):
... print(i)
...
0
1
2
3
4
>>> for i in range(1,n,2):
... print(i)
...
1
3
>>>
KeyboardInterrupt
>>>
barty @ more dotify3.py
# Copyright (c) 2013 Bart Massey
# Put dots between characters in a string
s = input("string to dotify? ")
dot_s = s[0]
for c in s[1:]:
dot_s = dot_s + '.' + c
print(dot_s)
barty @ emacs dotify3.py
barty @ python3
Python 3.2.3 (default, Sep 10 2012, 12:58:42)
[GCC 4.7.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> (1, 2)
(1, 2)
>>> (1, 2) + (3, 4)
(1, 2, 3, 4)
>>> (1, 2)[0] = 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
>>>
Last modified: Friday, 1 February 2013, 12:44 AM