-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter 02.py
More file actions
51 lines (39 loc) · 982 Bytes
/
Chapter 02.py
File metadata and controls
51 lines (39 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 2-1: String.
msg = "My name is John"
print(msg)
# 2-2: String.
msg = "And my name is Kate"
print(msg)
# 2-3: Variable and string.
name = "Kate"
print("Hello " + name + ", would you like to learn some Python today?")
# 2-4: Lower, upper, and title case.
print(name.lower())
print(name.upper())
print(name.title())
# 2-5: Quotation marks in string.
print('In the book Grit, Angela Duckworth says "Before work comes play"')
# 2-6: Variables and string.
famous_person = "Angela Duckworth"
message = 'In the book Grit, ' + famous_person + ' says "Before work comes play"'
print(message)
# 2-7: Stripped string.
name = " Kate "
print(name)
print(name.lstrip())
print(name.rstrip())
print(name.strip())
print("\n" + name)
print("\t" + name)
# 2-8: Math.
print(5 + 3)
print(24 / 3)
print(4 * 2)
print(12 - 4)
# 2-9: int to str.
favorite_number = 15
print('My favorite number is ' + str(favorite_number))
# 2-10: Comments.
# This is a comment
# 2-11: Python bible.
import this