Easy Spelunking Exercise
How do the relational operators act on strings? Let's figure this out.
Ordering of letters: (ASCII) ord("a") 97 0b01100001 ord("b") 98 0b01100010 ord("A") 65 0b01000001 ord("\n") 10 0b00001010 order a string dictioary ordering compare first if one lesser, report that as less repeat for succeeding charcters lexicographical lexicon: dictionary asc ord("0") 48 0b00110000
Reading
Read p0.pdf
, §§ 0-2.
Some New String Things (§ 3)
single or double
Let's get raw
format strings
Last login: Sun Aug 22 16:24:45 on ttys001
python
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) MAC:Mon Aug 23:10:08:webdev> python
Python 3.8.5 (default, Sep 4 2020, 02:22:02)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> meters_per_second = 2.997e8
>>> cm_per_second = meters_per_second*100
>>> in_per_second = cm_per_second/2.54
>>> mi_per_second = cm_per_second/(5280*12)
>>> mi_per_second
473011.36363636365
>>> mi_per_second = in_per_second/(5280*12)
>>> mi_per_second
186224.946313529
>>>
(base) MAC:Mon Aug 23:10:15:webdev> ssc
Last login: Mon Aug 23 08:12:11 2021 from 172.31.249.105
SERVER:Mon Aug 23:14:03:~> B
SERVER:Mon Aug 23:14:03:4240> cd Aug/23Aug21/
SERVER:Mon Aug 23:14:03:23Aug21> vi index.php
140398685042240
>>> hex(id(x))
'0x7fb11dbfb640'
>>> x[0] = 5
>>> hex(id(x))
'0x7fb11dbfb640'
>>> x
[5, 2, 3, 4, 5]
>>> zoo = ["tapir", True, 42, 1.414]
>>> type(zoo)
<class 'list'>
>>> zoo[0] = "anteater"
>>> zoo[0]
'anteater'
>>> zoo
['anteater', True, 42, 1.414]
>>> ##using the documentation is next
>>> x = [1,2,3,4,5,9]
>>> y = [k*k for k in x]
>>> y
[1, 4, 9, 16, 25, 81]
>>> z = [k*k*k for k in x if k*k > 10]
>>> z
[64, 125, 729]
>>>
Last login: Mon Aug 23 10:08:45 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) MAC:Tue Aug 24:10:02:python> cd
(base) MAC:Tue Aug 24:10:02:~> cd c20212022/S1/4240
(base) MAC:Tue Aug 24:10:02:4240> ls
0820.txt 0820F.txt Lab1 hello.py roster.txt students
(base) MAC:Tue Aug 24:10:02:4240> python hello.py
(base) MAC:Tue Aug 24:10:03:4240> python hello.py
Hello, World!
(base) MAC:Tue Aug 24:10:03:4240> python hello.py
Hello, World!
5**6 = 15625
(base) MAC:Tue Aug 24:10:04:4240> python hello.py
Hello, World!
5**6 = 15625
The rules of this ugly
game are too heinous for
mere mortals to witness
Traceback (most recent call last):
File "hello.py", line 9, in <module>
print(f"{k} {ord(k)}")
TypeError: ord() expected string of length 1, but int found
(base) MAC:Tue Aug 24:10:07:4240> python hello.py
Hello, World!
5**6 = 15625
The rules of this ugly
game are too heinous for
mere mortals to witness
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
58 :
59 ;
60 <
61 =
62 >
63 ?
(base) MAC:Tue Aug 24:10:08:4240> python hello.py
Hello, World!
5**6 = 15625
The rules of this ugly
game are too heinous for
mere mortals to witness
90 Z
91 [
92 \
93 ]
94 ^
95 _
96 `
97 a
98 b
99 c
100 d
101 e
102 f
103 g
104 h
105 i
106 j
107 k
108 l
109 m
110 n
111 o
112 p
113 q
114 r
115 s
116 t
117 u
118 v
119 w
(base) MAC:Tue Aug 24:10:09:4240>