- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_stringPython.py
More file actions
Latest commit
91 lines (58 loc) · 1.56 KB
/
Copy path10_stringPython.py
File metadata and controls
91 lines (58 loc) · 1.56 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
string1='''hello'''#multiline string
str1="hello"
str2="world"
#string Concact
print(str1+str2)
# 1) Case Conversion
stringOne="hello from python"
print(stringOne.capitalize()) #only first character of string
print(stringOne.title()) #capatalize the each 1st letter of string
print(stringOne.upper()) #all charcter to upper
print(stringOne.lower()) #all character to lower
print(stringOne.swapcase()) #case swapping
# 2) Alignment Method
s="hello"
print(s.center(10, '-'))
print(s.ljust(10, '-'))
print(s.rjust(10, '-'))
# 3) check Methods check whearther true or false
s2="hello"
print(s2.isalpha())
print(s2.isdigit())
print(s2.isalnum())
s3=" "
print(s3.isspace())
s4="hello"
print(s4.islower())
s5="HELLO"
print(s5.isupper())
s6="hello world"
print(s6.istitle())
#modify methods
s7="hello world"
print(s7.replace("world", "Python"))
s8=" hello "
print(s8.strip())
s9=" hello "
print(s9.lstrip())
s10=" aditya "
print(s10.rstrip())
#searching and counting
#find index of G first occurance
s11="Aditya Gaikwad"
print(s11.find("Gaikwad"))
#find last element of substring
s12="hello world"
print(s12.rfind("l"))
#print(s.rfind("l", 0, 5)) we can also specify the index
s13="banana"
print(s.count("a"))
#Splitting and Joining
s14="hello world"
print(s14.split()) # Output: ["hello", "world"]
s15="hello world"
print(s15.rsplit()) # Output: ["hello", "world"]
s16="hello\nworld"
print(s16.splitlines()) # Output: ["hello", "world"]
s17="-"
print(s17.join(["hello", "world"])) # Output: "hello-world"