>>> for item in range(6): ... print(item) ... 0 1 2 3 4 5 >>> for item in range(2,5): ... print(item) ... 2 3 4 >>> for item in range(2, 105, 7): ... print(item) ... 2 9 16 23 30 37 44 51 58 65 72 79 86 93 100 >>> for item in range(0, 1, .1): ... print(item) ... Traceback (most recent call last): File "", line 1, in TypeError: 'float' object cannot be interpreted as an integer >>> for item in range(5): ... print("Bart is a brat.") ... Bart is a brat. Bart is a brat. Bart is a brat. Bart is a brat. Bart is a brat. >>> for item in range(10, -1, -1): ... print(item) ... 10 9 8 7 6 5 4 3 2 1 0 >>> for item in reversed(range(0, 11)): ... print(item) ... 10 9 8 7 6 5 4 3 2 1 0 >>> x = ["a", "b", "c", "d", "e"] >>> for k in x: ... print(k) ... a b c d e >>> t = ("a", "b", "c", "d", "e") >>> for k in t: ... print(k) ... a b c d e >>> d = {"cat":"meow", "dog":"woof", "pig":"reeeet"} >>> >>> for k in d: ... print(k) ... cat dog pig >>> for k in d.values(): ... print(k) ... meow woof reeeet >>> d.values() dict_values(['meow', 'woof', 'reeeet']) >>> s = {5,2,9,0,"cow", "pig", "horse"} >>> for k in s: ... print(k) ... 0 cow 2 pig 5 horse 9 >>> for k in s: ... print(k) ... 0 cow 2 pig 5 horse 9 >>> ^D MAC:Mon Feb 28:08:45:0228> python Python 3.10.0 (v3.10.0:b494f5935c, Oct 4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> fp = open("sampler.txt", "r") >>> for k in fp: ... print(k, end="") ... abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !@#$%^&*() >>> fp.tell() 76 >>> fp.seek(0) 0 >>> guts = fp.read() >>> guts 'abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n1234567890\n!@#$%^&*()\n' >>> "def" in guts True >>> fp.close() >>> import os >>> files = os.listdir() >>> for k in files: ... print(k) ... sampler.txt >>> ^D MAC:Mon Feb 28:08:50:0228> vi copy.py MAC:Mon Feb 28:08:57:0228> python copy.py sampler.txt foo.txt MAC:Mon Feb 28:08:58:0228> diff sampler.txt foo.txt MAC:Mon Feb 28:08:58:0228> cat foo.txt abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !@#$%^&*() MAC:Mon Feb 28:08:58:0228> cp copy.py copy_better.py MAC:Mon Feb 28:08:58:0228> vi copy_better.py MAC:Mon Feb 28:09:01:0228> python copy_better.py sampler.txt foo.txt MAC:Mon Feb 28:09:01:0228> cat foo.txt abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 !@#$%^&*() MAC:Mon Feb 28:09:01:0228> python copy_better.py heffalump.imagainary foo.txt You are attempting to copy from a nonexistent file. MAC:Mon Feb 28:09:02:0228> python copy_better.py Usage: python copy.py donor recipient MAC:Mon Feb 28:09:02:0228> vi zz.py MAC:Mon Feb 28:09:16:0228> cp ~/data/scrabble.txt . MAC:Mon Feb 28:09:16:0228> !p python zz.py bezazz bezazzes pazazz pazazzes pizazz pizazzes pizazzy pizzaz pizzazes pizzazz pizzazzes pizzazzy razzamatazz razzamatazzes razzmatazz razzmatazzes zizzle zizzled zizzles zizzling zyzzyva zyzzyvas zzz MAC:Mon Feb 28:09:16:0228> MAC:Mon Feb 28:09:16:0228> !vi vi zz.py MAC:Mon Feb 28:09:16:0228> !p python zz.py bezazz bezazzes pazazz pazazzes pizazz pizazzes pizazzy pizzaz pizzazes pizzazz pizzazzes pizzazzy razzamatazz razzamatazzes razzmatazz razzmatazzes zizzle zizzled zizzles zizzling zyzzyva zyzzyvas zzz MAC:Mon Feb 28:09:16:0228> !vi vi zz.py