Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "copyright", "credits" or "license()" for more information. >>> ord('a') 97 >>> ord('A') 65 >>> print('hello') hello >>> for character in 'hello': print(character) h e l l o >>> for number in range(5): print(number) 0 1 2 3 4 >>> for number in [1,2,3,4]: print(number) 1 2 3 4 >>> print('hello') hello >>> Print('hello') Traceback (most recent call last): File "", line 1, in Print('hello') NameError: name 'Print' is not defined >>> print >>> print(print) >>> print('5','gorilla',55) 5 gorilla 55 >>> '\n' '\n' >>> print('\n') >>> '56' '56' >>> 56 56 >>> print('56') 56 >>> print(56) 56 >>> print('hello) SyntaxError: EOL while scanning string literal >>> SyntaxError: EOL while scanning string literal SyntaxError: invalid syntax >>> 'hello' 'hello' >>> print('hello') hello >>> print('hello' 'gorilla') hellogorilla >>> "hello" 'hello' >>> '''hello''' 'hello' >>> def plus(item,item): answer = item+item SyntaxError: duplicate argument 'item' in function definition >>> def plus(item1,item2): answer = item1+item2 print(answer) return(answer) >>> plus(5,6) 11 11 >>> output = plus(5,6) 11 >>> output 11 >>> def print_plus(item1,item2): answer = item1+item2 print(answer) >>> output2 - print_plus(5,6) Traceback (most recent call last): File "", line 1, in output2 - print_plus(5,6) NameError: name 'output2' is not defined >>> output2 = print_plus(5,6) 11 >>> output2 >>> this Traceback (most recent call last): File "", line 1, in this NameError: name 'this' is not defined >>> output2 >>> None >>> output2 = None >>> output2 == Noe Traceback (most recent call last): File "", line 1, in output2 == Noe NameError: name 'Noe' is not defined >>> output2 == None True >>> None >>> plus(5,6) + plus(7,8) 11 15 26 >>> print_plus(5,6) + print_plus(7,8) 11 15 Traceback (most recent call last): File "", line 1, in print_plus(5,6) + print_plus(7,8) TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType' >>> print() >>> type('abc') >>> type(5) >>> type(5.0) >>> type(True) >>> type(print) >>> type(None) >>> type([1,2,3]) >>> "John's house" "John's house" >>> 'John's house' SyntaxError: invalid syntax >>> 'John\'s house' "John's house" >>> 'John\'s "house"' 'John\'s "house"' >>> '''John\'s house''' "John's house" >>> 'Escape characters: \n \t \' ' "Escape characters: \n \t ' " >>> print('Escape characters: \n \t \' ') Escape characters: ' >>> print('Escape characters: newline: \n tab: \t single-quote\' ') Escape characters: newline: tab: single-quote' >>> '''There is a newline here''' 'There is a newline\nhere' >>> .111111111111111111111111111111111111111111111111111119 0.1111111111111111 >>> 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 >>> 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.0 1e+91 >>> 5+5j (5+5j) >>> 5+5 10 >>> def plus(item1,item2): return(item1+item2) >>> plus(5,5) 10 >>> 5/10 0.5 >>> 56/103 0.5436893203883495 >>> 5/2 2.5 >>> 5//2 2 >>> -5//2 -3 >>> import math >>> math.ceil(2.5) 3 >>> math.floor(2.5) 2 >>> math.trunc(2.5) 2 >>> math.floor(-2.5) -3 >>> math.trunc(-2.5) -2 >>> round(2.5) 2 >>> round(2.6) 3 >>> 5%2 1 >>> 13%7 6 >>> 6%6 0 >>> 50%7 1 >>> 60%12 0 >>> 72%12 0 >>> 61%12 1 >>> 73%12 1 >>> output = plus(5,7) >>> 'hello' + ' ' + 'hello' 'hello hello' >>> 5+5 10 >>> 'hello' + 5 Traceback (most recent call last): File "", line 1, in 'hello' + 5 TypeError: Can't convert 'int' object to str implicitly >>> 5*45 225 >>> 'hello' * 5 'hellohellohellohellohello' >>> 'hello' * 'hello' Traceback (most recent call last): File "", line 1, in 'hello' * 'hello' TypeError: can't multiply sequence by non-int of type 'str' >>> 'hello' ** 4 Traceback (most recent call last): File "", line 1, in 'hello' ** 4 TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' >>> 2 ** 4 16 >>> 'hello' / 4 Traceback (most recent call last): File "", line 1, in 'hello' / 4 TypeError: unsupported operand type(s) for /: 'str' and 'int' >>> len('hello') 5 >>> str(5) '5' >>> str(print) '' >>> print('hello') hello >>> 'hello' 'hello' >>> def make_number_and_word_string(number,word): return(word+str(number)) >>> make_number_and_word_string(5,'hello') 'hello5' >>> print(make_number_and_word_string(5,'hello')) hello5 >>> 'hello'+5 Traceback (most recent call last): File "", line 1, in 'hello'+5 TypeError: Can't convert 'int' object to str implicitly >>> 'hello'+'5' 'hello5' >>> >>> 'hello'+str(5) 'hello5' >>> def print_stuff_several_times(number,stuff): ## this takes two parameters ## number is the amount of times stuff should be printed ## stuff is what you want printed print(str(stuff)*number) >>> print_stuff_several_times(5,57) 5757575757 >>> print_stuff_several_times(5,'junk') junkjunkjunkjunkjunk >>> int(5.1) 5 >>> int(-5.1) -5 >>> float(5) 5.0 >>> int('5') 5 >>> float('5.1') 5.1 >>> float('5') 5.0 >>> int('5.1') Traceback (most recent call last): File "", line 1, in int('5.1') ValueError: invalid literal for int() with base 10: '5.1' >>> float('five') Traceback (most recent call last): File "", line 1, in float('five') ValueError: could not convert string to float: five >>>