Self-paced introduction, part 1
Goals
- Get to know the Python shell
- Meet some useful Python data types
- Practice using variables
- Learn why tracebacks are useful
Steps
a = "Hello"
Strings
"Hello, world""Alice""Alice" + "Walker""Alice " + "Walker""Alice" 'Alice''Alice's restaurant'
Command history
Variables
Alicename = "Alice" print name
Output
"Alice"name = "Alice"name = "Alice" name name = "Bob" namename = "Alice"name="Alice"
The return of strings
h = "Hello" w = "World" print h + wmy_string = "Alpha " + "Beta " + "Gamma " + "Delta" print my_stringlen("Alice") len("") len(my_string)Note that we can dolen(my_string)
because you assigned a value to the variablemy_string
earlier. If you used a variable name you hadn't assigned a value to yet, likelen(foo)
, what would happen?name + len(name)
Types
len(name) len("1") len(1)type(name) type("1") type(1)
Arithmetic
2 + 2 1.5 + 2.254 - 2 100 - 0.5 0 - 22 * 34 / 2 1 / 21.0 / 23/4 + 1/43.0/4 + 1.0/4 3.0/4.0 + 1.0/4.0
End of part 1
Next Step:
Back to Before the preconference