-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonStringMethods.py
More file actions
187 lines (122 loc) · 3.79 KB
/
Copy pathpythonStringMethods.py
File metadata and controls
187 lines (122 loc) · 3.79 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 14 05:01:06 2024
@author: SÜLEYMAN BEYYY
"""
# Split Method
'''
It performs fragmentation based on a character specified in the character string.
'''
'''
message = 'Hello, There.'
message = message.split(',')
print(message)
'''
'''
It sends us a list by splitting the string into pieces using the ',' character.
When we do not send a parameter to the split method, division is performed using the space character.
'''
# Upper Method
'''
Converts characters to uppercase.
'''
'''
message = 'hello there.'
message = message.upper()
print(message)
'''
'''
** title(), The method converts the first letter of each word in the string to uppercase.
** The capitalize() Method capitalizes only the first letter of the first word in the string.
'''
'''
message = 'hello there.'
message1 = message.title()
message2 = message.capitalize()
print(message1)
print(message2)
'''
# Strip Method
'''
The Strip method deletes whitespace characters at the beginning and end of the string.
'''
'''
username = ' ....... '
x = username.strip()
print('My username is {}'.format(x))
'''
'''
If we want the strip() method to delete the characters we specify, we need to send this character as a parameter.
'''
'''
username = ' .......! '
x = username.strip()
y = x.strip('!')
print('My username is {}'.format(y))
'''
# Replacement Method
'''
The replace method is used to replace an expression in a character string.
'''
'''
message = 'My name is ...* .....'
message = message.replace('...*', '!!!')
print(message)
'''
'''
We can use replace() methods repeatedly. We can update Turkish characters, space characters and '@' sign in the url with the following expression.
'''
'''
url = '...'
url = url.replace(' ','-').replace('@','').replace('ö','o').replace('ü','u').replace('ş','s').replace('ü','u')
print(url)
'''
# Find Method
'''
The find method searches within the given string expression and returns the first index number it finds. If it can't find it, it returns an exception-1.
'''
'''
txt = 'My name is ... '
x1 = txt.find('...')
print(x1)
x2 = txt.find('...*')
print(x2)
'''
# Index Method
'''
The index method searches within the given string expression and returns the first index number it finds. If it cannot find it, it returns exception, unlike the find method.
'''
'''
txt = 'My name is ...'
x = txt.index('...')
print(x)
'''
'''
** We can also specify a search scope for the index and find method.
index("searched expression", "start index", "end index")/find("searched expression", "start index", "end index")
'''
'''
txt = 'My name is ...'
x1 = txt.index('...',10,14)
x2 = txt.find('...',10,14)
print(x1)
print(x2)
'''
'''
website = "http://www.mehmetakif.edu.tr"
course = "Python Lesson: Start-to-End Python Programming Course (14 Weeks)"
print(website.count('a')) -> How many a characters are there in 'website'?
print(website.startswith('www')) -> Does “website” start with “www”?
print(website.startswith('http'))
print(website.endswith('com')) -> Does “website” end in 'com'?
print(website.endswith('.tr'))
print(course.isalpha()) -> Are the characters in 'course' all alphabetical?
print('hello'.isalpha())
print(course.isdigit()) -> Are all the characters in 'course' numeric?
print('123'.isdigit())
'''
'''
print('Contents'.center(50,'*')) -> There will be a total of 50 characters as ****Content****.
print('Contents'.ljust(50,'*')) -> There will be a total of 50 characters in the form, Content *********.
print('Contents'.rjust(50,'*')) -> There will be a total of 50 characters in the form ********* Contents.
'''