-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringindexing.py
57 lines (55 loc) · 1.41 KB
/
stringindexing.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
name="Sheeza"
print(name[0])
print(name[1])
print(name[2])
print(name[3])
print(name[4])
print(name[-5])
print(name[-6])
print(name[2:5])
print(name[:3])
print(name[4:])
print(name[:0])
print(name[:1])
print(name[:6])
print(name[5:6])
print(name[6:])
print(name[:])
print(name[::2])
print(name[::1])#stepstrings
print(name[1:1:2])#Steping strings
print(name[::-1])#reverse string
print(name[2::-1])#reversing slice of string
name = "Alton"
print(name[::2])
for letter in name:#iterating strings
print(letter)
name=input()
new_name=""
for i in name:
if i.lower()=='i':
new_name+=i.upper()
elif i.islower()=='o':
new_name+=i.upper()
else:
new_name=name
print(new_name)
for letter in name[::-1]:
print(letter)
print(len(name))#for finding length
sentence="I am fine really what abot you?"
length=len(sentence)
mid=int(length/2)
print(sentence[:mid])
print(sentence[:mid].count("e"))
print(sentence[mid:])
print(sentence[mid:].count("e"))
print(sentence.count("a"))#for counting
print(sentence[:8].count("a"))
#To find the index of where a character or a sub-string occurs within a string, we can use the find method.
#Now lets start
# to find space index
print(sentence.find(""))
print(sentence.find("really"))
#find method with three arguments such as string starting index ,ending index and string itself
print(sentence.find("fine",9,13))