Skip to content

Commit 8be734a

Browse files
committed
added string-escaping
1 parent 5d347ed commit 8be734a

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

String-escape/escape.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Python code to demonstrate escape character
2+
# string
3+
4+
example = "Python\tis\tProgramming\tLanguage"
5+
6+
print ("The string after resolving escape character is : ")
7+
print (example)
8+
9+
example = "Python\nis\nProgramming\nLanguage"
10+
print ("The string after resolving escape character is : ")
11+
print (example)
12+
13+
print ("\\")
14+
print ("\'")
15+
print ("\"")
16+
print ("\u9132")
17+
print ("\x25")
18+
print("\a")
19+
print("python\b")
20+
print("python\bc")
21+
print("python\r")

String-escape/string-repr.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Python code to demonstrate printing
2+
# escape characters from repr()
3+
4+
# initializing target string
5+
example = "I\nLove\tworld"
6+
7+
print ("The string without repr() is : ")
8+
print (example)
9+
10+
print ("\r")
11+
12+
print ("The string after using repr() is : ")
13+
print (repr(example))
14+
15+
16+
# Python code to demonstrate printing
17+
# escape characters from "r" or "R"
18+
19+
# initializing target string
20+
ch = "I\nLove\tWorld"
21+
22+
print ("The string without r / R is : ")
23+
print (ch)
24+
25+
#print ("\r")
26+
27+
# using "r" to prevent resolution
28+
ch1 = r"I\nLove\tWorld"
29+
30+
print ("The string after using r is : ")
31+
print (ch1)
32+
33+
#print ("\r")
34+
35+
# using "R" to prevent resolution
36+
ch2 = R"I\nLove\tWorld"
37+
38+
print ("The string after using R is : ")
39+
print (ch2)

0 commit comments

Comments
 (0)