FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python_learning/string_functions_3.py at main · regretfool/python_learning · GitHub
regretfool
/
python_learning
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python_learning
/
string_functions_3.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (54 loc) · 1.72 KB
Breadcrumbs
python_learning
/
string_functions_3.py
Copy path
File metadata and controls
64 lines (54 loc) · 1.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# CLEANING
# Clean whitespaces
# only left only right
# lstrip() -> " dog " <- rstrip()
# strip() - both left and right
# Use strip for user inputs since we don't know where they could enter spaces! Doesn't remove spaces inside
text
=
" Engineering"
.
lstrip
()
print
(
text
)
text
=
"Engineering "
.
rstrip
()
print
(
text
)
text
=
" Engineering "
.
strip
()
print
(
text
)
# strip() Doesn't remove spaces inside
text
=
" Data Engineering "
.
strip
()
print
(
text
)
# We can also remove special characters
text
=
"###Abc###"
.
strip
(
"#"
)
print
(
text
)
# We can check how many whitespaces we have
text
=
" Engineering"
print
(
len
(
text
))
print
(
len
(
text
.
strip
()))
#
nr_of_spaces
=
len
(
text
)
-
len
(
text
.
strip
())
# 2 whitespaces
is_clean
=
len
(
text
)
==
len
(
text
.
strip
())
# False - so not equal to cleaned up string
print
(
"Nr of spaces:"
,
nr_of_spaces
)
print
(
"Is my data clean?"
,
is_clean
)
# Clean cases
text
=
"python PROGRAMMING"
print
(
text
.
lower
())
print
(
text
.
upper
())
print
(
text
.
capitalize
())
print
(
text
.
swapcase
())
# We can use this to compare data from database with what we want etc.
search
=
"Email "
.
lower
().
strip
()
data
=
" emAil"
.
lower
().
strip
()
print
(
search
==
data
)
# Challenge. Make it look like name:maria | role: data engineer | age: 27
text
=
"968-Maria, ( D@t@ Engineer );; 27y "
text
=
text
.
replace
(
"968-"
,
""
)
text
=
text
.
replace
(
"@"
,
"a"
)
text
=
text
.
replace
(
" ( "
,
""
)
text
=
text
.
replace
(
" )"
,
""
)
text
=
text
.
replace
(
";; "
,
","
)
text
=
text
.
replace
(
"y"
,
""
)
text
=
text
.
rstrip
()
text
=
text
.
lower
()
text
=
text
.
lstrip
()
text
=
text
.
split
(
","
)
# text[0] = text[0].replace(" ", "name: ")
# text[1] = text[1].replace(" ", "role: ")
# text[2] = text[2].replace(" ", "age: ")
print
(
f"name:
{
text
[
0
]
}
| role:
{
text
[
1
]
}
| age:
{
text
[
2
]
}
"
)
Back
|
FazBrowse Home
|
New Git URL