-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscape_Characters.py
74 lines (39 loc) · 2.29 KB
/
Escape_Characters.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
# Escape Characters
# JCBrent
#
# The following is a code hack to eliminate ASCii encoding errors if in a foreign country
# -*- coding: utf-8 -*-
print("Escape Characters in Python")
print("----------------------------\n")
print("\\r # Carriage return escape")
print('Note: the octothorpe "#" (hash or mesh) character is for comments - almost an escape character if you think about it.\n\n')
x_backslash = "\\\\"
print("The backslash character is escaped by typing a slash in front of it, as in {0} \n".format(x_backslash)) # py2.7 format (%s) \n" % x_backslash)
print("The backslash character is escaped by typing a slash in front of it, as in %s using the raw string = percent s \n" % x_backslash)
y_single_quote = "(\\')"
print(" \\' = single quote escape %s \n"% y_single_quote)
print(" \\a = the ASCii bell (BEL) character escape\n")
print(" \\b = the backspace escape character \n")
print(' \\f = the form feed escape character ')
print(" The form feed isn't used in Python - if importing data from another language this might be needed \n")
print(" \\n = the new line escape character (preferred over form feed in Python) ")
print(" \\N{name} = the Unicode database character escape in Py2.7\n")
print(" \\r = carriage return escape character - not used in Python... \r")
print(" The carriage return isn't used in Python - instead Python uses a single line return \n")
print(" \\t = horizontal tab character escape character \n")
print(" \\uxxxx = 16bit Hex value escape character - Unicode only \n")
print(" \\Uxxxxxxxx = 32 bit Hex value escape character - Unicode only \n")
print( " \\v = the verticle tab character escape character \n")
print (" \\ooo = the Octal character escape character with the value ooo \f")
print (" \\xhh = the Hex value escape character with the value of hh \n")
# -------------
print('Set the message variable equal to any string containing a new-line escape sequence')
message = "One\ntwo"
print(message); print()
print('Add a string to the mountains variable that when printed results in: /\/\/\ ')
print('You will need to use an escape sequence more than once!')
mountains = "/\\/\\/\\"
print(mountains); print()
print('Set the quotation variable to any string that contains an escaped double quotation mark \n')
quotation = "Time\'s up"
print(quotation)