-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit1_notes_printing_strings.py
69 lines (57 loc) · 2.1 KB
/
unit1_notes_printing_strings.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Name: Mr. Callaghan
Title: Unit 1 notes - printing strings
Description: Printing strings to the console and escape sequences
"""
# Printing String Values
# STRING - Our first 'type' of value in Python. It is a series of characters surrounded by single, double, or triple quotes.
# TYPE - A category of data in a programming langauge that determines what kinds of operations can be performed.
# Classes, like the Turtle class, are types.
# The type() function will return the type of a value
# e.g.,
type("test string") # in shell
print("Hello, world.") # printing a string
# printing quotes
print ("Mr. C said, 'Hello, class'!")
print ('Mr. C said, "Hello, class!"')
print ("""Mr. C said, 'Hello, class'!""")
print()
# triple quoted string: displays text WITH typed formatting
print ("""This is a triple-quoted string
and is displays text with my typed
formatting included!""")
# ASCII art example:
print(
"""
_.---._ /\\
./' "--`\//
./ o \ .-----.
/./\ )______ \__ \ ( help! )
./ / /\ \ | \ \ \ \ /`-----'
/ / \ \ | |\ \ \7--- ooo ooo ooo ooo ooo ooo
"""
)
print ()
# line continuation - including end="" as the final argument to a print function removes the implicit new line character included in a print statement
# e.g.,
print ("This is line 1, ", end="")
print ("This is line 2,", end=' ')
print ("This is line 3.")
print("This is line 4.")
# input function - also displays to the console, but pauses execution and waits for the user to type and press enter
# unlike print(), input() accepts only one arguement
input("Press enter to comtinue...")
# input("Press enter to continue..." , "Please.") # error
# ESCAPE SEQUENCES - characters used inside of strings to gain more control over the behavior of the text.
# \t (tab)
print ("Name\tAge\tJob\t")
print ("Matt Callaghan\t32\tTeacher")
# \n (new line)
print ("Insert new line below!\n")
print ("Line 2")
# \\ (backslash)
print ("MM\\DD\\YYYY")
# \" \' (quotation)
print ("Mr. C said, \"Hello, class!\"")
print ()
# CHALLENGE: Go back and re-try the printing challenge prompts