-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththird.py
More file actions
49 lines (35 loc) · 1.54 KB
/
third.py
File metadata and controls
49 lines (35 loc) · 1.54 KB
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
# -----------------------------------------------STRINGS-------------------------------------------------------
a = 'Books' # Single quoted string
b = "Books" # Double quoted string
C = '''Books''' # Triple quoted string
# -----------------------------------------------STRING SLICING-------------------------------------------------------
name = "Books"
nameshort = name[0:3] # start from index 0 all the way till 3 (excluding 3)
print(nameshort)
character1 = name[1]
character2 = name[2]
print(character1, character2)
# -5 -4 -3 -2 -1
# B o o k s
print(name[-4: -1]) #ook
print(name[1:4])
print(name[:4]) # is same as print(name[0:4])
print(name[1:]) # is same as print(name[1:5])
print(name[1:5])
# -----------------------------------------------SLICING WITH SKIP VALUE-------------------------------------------------------
word = "amazing"
word [1: 6: 2] # "mzn" [start: end: skip]
# -----------------------------------------------STRING FUNCTIONS-------------------------------------------------------
name = "books"
print(len(name))
print(name.endswith("oks"))
print(name.startswith("Bo"))
print(name.capitalize())
print(name.count("o")) # Books
print(name.find("ks")) # index --> 3
print(name.replace("o", "n")) # Bnnks
# -----------------------------------------------ESCAPE SEQUENCE CHARACTERS-------------------------------------------------------
# Example:\n, \t, \', \\ etc.
# newline Tab Singlequote backslash
a = 'John is a good boy\nbut not a bad \'boy\''
print(a)