diff --git a/Advanced/CoRoutine/CoRoutine.py b/Advanced/CoRoutine/CoRoutine.py index 81605bc..4ca1ba0 100755 --- a/Advanced/CoRoutine/CoRoutine.py +++ b/Advanced/CoRoutine/CoRoutine.py @@ -37,7 +37,7 @@ def keep_sorted(): # Start the generator g.next() # Send stuff - print g.send('zzz') - print g.send('Hi there') - print 'Sorted list is {0:s}'.format(g.next()) + print(g.send('zzz')) + print(g.send('Hi there')) + print('Sorted list is {0:s}'.format(g.next())) g.close() diff --git a/Advanced/RomeoAndJuliet/util/parser.py b/Advanced/RomeoAndJuliet/util/parser.py index 2c44fc6..0c02e1c 100755 --- a/Advanced/RomeoAndJuliet/util/parser.py +++ b/Advanced/RomeoAndJuliet/util/parser.py @@ -154,15 +154,14 @@ def get_acts_scenes_actors(): s.add_actor('c') s.add_actor('d') g = s.gen_actors() - g - print next(g) - print next(g) - print next(g) - print next(g) - print next(g) + print(next(g)) + print(next(g)) + print(next(g)) + print(next(g)) + print(next(g)) # print next(s) # print next(s) # print next(s) # print next(s) # print next(s) - \ No newline at end of file + diff --git a/Beginners/ExampleFunctions/A_functions_simple.py b/Beginners/ExampleFunctions/A_functions_simple.py index 901877f..2bd73ef 100644 --- a/Beginners/ExampleFunctions/A_functions_simple.py +++ b/Beginners/ExampleFunctions/A_functions_simple.py @@ -11,14 +11,14 @@ ################### def noArgs(): """Function that takes no arguments.""" - print ' noArgs(): No arguments' + print(' noArgs(): No arguments') def twoArgs(a, b): """Function that takes two arguments.""" - print ' twoArgs(): a=%s, b=%s' % (a, b) + print (' twoArgs(): a=%s, b=%s' % (a, b)) def main(): - print 'callSimple():' + print('callSimple():') noArgs() twoArgs(12, 34) twoArgs(b='b_given', a='a_given') diff --git a/Beginners/ExampleFunctions/B_functions_default.py b/Beginners/ExampleFunctions/B_functions_default.py index c6a4c8c..e818466 100644 --- a/Beginners/ExampleFunctions/B_functions_default.py +++ b/Beginners/ExampleFunctions/B_functions_default.py @@ -16,10 +16,10 @@ # Simple functions, with defaults. ################################## def twoArgsOneDefault(a, b='default_value'): - print ' a=%s, b=%s' % (a, b) + print(' a=%s, b=%s' % (a, b)) def main(): - print 'callTwoArgsOneDefault():' + print ('callTwoArgsOneDefault():') twoArgsOneDefault('a_only') twoArgsOneDefault('a_value', b='b_given') diff --git a/Beginners/ExampleFunctions/C_functions_default_mutable.py b/Beginners/ExampleFunctions/C_functions_default_mutable.py index f96b57e..f3de327 100644 --- a/Beginners/ExampleFunctions/C_functions_default_mutable.py +++ b/Beginners/ExampleFunctions/C_functions_default_mutable.py @@ -28,13 +28,13 @@ def defaultMutableFix(a=x): def main(): # defaultMutableCatch() - print 'defaultMutableCatch():', defaultMutableCatch() - print 'defaultMutableCatch():', defaultMutableCatch([]) - print 'defaultMutableCatch():', defaultMutableCatch() + print('defaultMutableCatch():', defaultMutableCatch()) + print('defaultMutableCatch():', defaultMutableCatch([])) + print('defaultMutableCatch():', defaultMutableCatch()) # defaultMutableFix() - print 'defaultMutableFix():', defaultMutableFix() - print 'defaultMutableFix():', defaultMutableFix() - print 'defaultMutableFix():', defaultMutableFix() + print('defaultMutableFix():', defaultMutableFix()) + print('defaultMutableFix():', defaultMutableFix()) + print('defaultMutableFix():', defaultMutableFix()) if __name__ == '__main__': main() diff --git a/Beginners/ExampleFunctions/D_functions_parrot.py b/Beginners/ExampleFunctions/D_functions_parrot.py index b70b175..bc0aee0 100644 --- a/Beginners/ExampleFunctions/D_functions_parrot.py +++ b/Beginners/ExampleFunctions/D_functions_parrot.py @@ -18,20 +18,20 @@ def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): - print "-- This parrot wouldn't", action, - print "if you put", voltage, "volts through it." - print "-- Lovely plumage, the", type - print "-- It's", state, "!" + print("-- This parrot wouldn't", action) + print("if you put", voltage, "volts through it.") + print("-- Lovely plumage, the", type) + print("-- It's", state, "!") def main(): parrot(1000) - print + print("\n") parrot(action='VOOOOOM', voltage=1000000) - print + print("\n") parrot('a thousand', state='pushing up the daisies') - print + print("\n") parrot('a million', 'bereft of life', 'jump') - print + print("\n") # These will raise a SyntaxError # parrot() # required argument missing # parrot(voltage=5.0, 'dead') # non-keyword argument following keyword diff --git a/Beginners/ExampleFunctions/E_functions_cheeseshop.py b/Beginners/ExampleFunctions/E_functions_cheeseshop.py index 4392b54..b95ab32 100644 --- a/Beginners/ExampleFunctions/E_functions_cheeseshop.py +++ b/Beginners/ExampleFunctions/E_functions_cheeseshop.py @@ -17,13 +17,13 @@ # With keyword arguments. ######################### def cheeseshop(kind, *args, **kwargs): - print "-- Do you have any", kind, "?" - print " *args ".center(40, '-') + print("-- Do you have any", kind, "?") + print(" *args ".center(40, '-')) pprint.pprint(args) - print " *args ".center(40, '-') - print " *kwargs ".center(40, '-') + print(" *args ".center(40, '-')) + print(" *kwargs ".center(40, '-')) pprint.pprint(kwargs) - print " *kwargs ".center(40, '-') + print(" *kwargs ".center(40, '-')) def main(): cheeseshop( diff --git a/Beginners/ExampleFunctions/F_functions_unpack_args.py b/Beginners/ExampleFunctions/F_functions_unpack_args.py index 28b888c..5b3c117 100644 --- a/Beginners/ExampleFunctions/F_functions_unpack_args.py +++ b/Beginners/ExampleFunctions/F_functions_unpack_args.py @@ -8,19 +8,19 @@ def unpackArgs(*args): for arg in args: - print type(arg), arg - print + print(type(arg), arg) + print("\n") def main(): - print 'callUnpackArgs():' - print 'Specific arguments:' + print('callUnpackArgs():') + print('Specific arguments:') unpackArgs(0,1,2,3) l = ['a', 'b', 'c', 'd'] - print 'Single list argument:' + print('Single list argument:') unpackArgs(l) - print 'Unpacked list argument:' + print('Unpacked list argument:') unpackArgs(*l) - print 'Single value unpacked' + print('Single value unpacked') unpackArgs(*'hello') if __name__ == '__main__': diff --git a/Beginners/ExampleFunctions/G_functions_unpack_kwargs.py b/Beginners/ExampleFunctions/G_functions_unpack_kwargs.py index 5d454eb..2e64931 100644 --- a/Beginners/ExampleFunctions/G_functions_unpack_kwargs.py +++ b/Beginners/ExampleFunctions/G_functions_unpack_kwargs.py @@ -10,18 +10,18 @@ def unpackKwargs(**kwargs): keys = kwargs.keys() keys.sort() for kw in keys: - print kw, ":", kwargs[kw] + print(kw, ":", kwargs[kw]) def main(): - print 'callUnpackKwargs():' - print 'Specific arguments:' + print('callUnpackKwargs():') + print('Specific arguments:') unpackKwargs(name='python', version=2.6) d = { 'name' : 'python', 'version' : 2.6, } - print - print 'Unpacked arguments:' + print("\n") + print('Unpacked arguments:') unpackKwargs(**d) if __name__ == '__main__': diff --git a/Beginners/Functions/ArgsKwargs.py b/Beginners/Functions/ArgsKwargs.py index 2e28274..2efd67a 100644 --- a/Beginners/Functions/ArgsKwargs.py +++ b/Beginners/Functions/ArgsKwargs.py @@ -9,23 +9,23 @@ def f(x, y, z): # print "x=%s y=%s, z=%s" % (x, y, z) return (x + y) / float(z) -print f(10, 5, 3) +print(f(10, 5, 3)) x = 20 y = 10 z = 3 # using kwargs -print f(x=x, y=y, z=z) +print(f(x=x, y=y, z=z)) # using args and kwargs -print f(y, x, z=2) +print(f(y, x, z=2)) # using args and kwargs out of order -print f(z=3, y=x, x=y) +print(f(z=3, y=x, x=y)) # all x -print f(z=x, y=x, x=x) +print(f(z=x, y=x, x=x)) """ With defaults @@ -36,15 +36,15 @@ def ff(x=20, y=10, z=3): # print "x=%s y=%s, z=%s" % (x, y, z) return (x + y) / float(z) -print ff(10, 5, 3) +print(ff(10, 5, 3)) # using args -print ff(10) +print(ff(10)) # using kwargs -print ff(z=10) +print(ff(z=10)) x = 20 -print ff(z=x, y=x) +print(ff(z=x, y=x)) diff --git a/Beginners/basics.py b/Beginners/basics.py index c21b826..9c25d2f 100644 --- a/Beginners/basics.py +++ b/Beginners/basics.py @@ -1,13 +1,13 @@ # Given x = 10000.0 y = 3.0 -print x / y -print 10000 / 3 +print(x / y) +print(10000 / 3) # What is happening? # Given -print x - 1 / y -print (x - 1) / y +print(x - 1 / y) +print((x - 1) / y) # What is happening? # Given diff --git a/First.py b/First.py index 14ffa4f..14418f2 100755 --- a/First.py +++ b/First.py @@ -7,7 +7,7 @@ """ def main(): - print 'Hi there' + print('Hi there') if __name__ == '__main__': main() diff --git a/Intermediate/Histogram/DictHistogram.py b/Intermediate/Histogram/DictHistogram.py index 803ca23..2094206 100755 --- a/Intermediate/Histogram/DictHistogram.py +++ b/Intermediate/Histogram/DictHistogram.py @@ -60,7 +60,7 @@ def pprint_histogram(d, bucket_size, char='+', width=80, key_format='%6.3f'): char is the character to use for the histogram bars. width is the total width to use. key_format is used to turn the keys into strings.""" - print pformat_histogram(d, bucket_size, char, width, key_format) + print(pformat_histogram(d, bucket_size, char, width, key_format)) def pformat_histogram(d, bucket_size, char='+', width=80, key_format='%6.3f'): diff --git a/Intermediate/RandomWords/RandomWords.py b/Intermediate/RandomWords/RandomWords.py index 4a0c99f..6f735fe 100755 --- a/Intermediate/RandomWords/RandomWords.py +++ b/Intermediate/RandomWords/RandomWords.py @@ -43,8 +43,8 @@ def main(): break max_len = max([len(w) for w in words]) for n in range(max_len): - print '%4d: %s' % (n, ' '.join(randomWords(words, n))) + print('%4d: %s' % (n, ' '.join(randomWords(words, n)))) if __name__ == '__main__': main() - print 'Bye, bye.' + print('Bye, bye.') diff --git a/Intermediate/RegexMapping/RegexMap.py b/Intermediate/RegexMapping/RegexMap.py index deeae76..0fda321 100755 --- a/Intermediate/RegexMapping/RegexMap.py +++ b/Intermediate/RegexMapping/RegexMap.py @@ -48,7 +48,7 @@ def main(): Hello world 42""" result = matchLines(text.split('\n')) - print result + print(result) if __name__ == '__main__': main()