-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13string.py
More file actions
97 lines (49 loc) · 1.37 KB
/
13string.py
File metadata and controls
97 lines (49 loc) · 1.37 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
string1="Hello World"
print(string1)
string2='Hello World2'
print(string2)
string3="Ram's"
print(string3)
string4='''Ram is a boy'''
print(string4)
#accessing characters of a string
first=string1[4]
print(first)
last=string1[-1]
print(last)
#slicing
sliced=string1[0:5]
print(sliced)
#looping
for char in string1:
print(char)
#length of string
print(len(string1))
#concatenation
string5=string1+string2
print(string5)
#repetation
string6=string1*3
print(string6)
#membership
print('World' in string1) #returns true if 'World' is present in string1
#immutable
#string1[0]='H' #strings are immutable
#methods of strings
string7="hello world,how are you"
print("Mehods of string")
#upper
print(string7.upper()) #all in caps
#lower
print(string7.lower()) #all in small
#title
print(string7.title()) #first letter of each word in caps
#split
print(string7.split(',')) #splitting string by comma,returns list
print(string7.split()) #by default delimiter is space
#strip()
print(string7.strip()) #removes leading and trailing(after end of string) spaces
#find()
print(string7.find('w')) #returns index of first occurence of w
print(string7.find('ld')) #returns index of first occurence of o
print(string7.find('mango')) #returns -1 if not found