-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMethod.py
More file actions
55 lines (36 loc) · 1.28 KB
/
StringMethod.py
File metadata and controls
55 lines (36 loc) · 1.28 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
"""text = "Hello, World!"
upper_text = text.upper() # "HELLO, WORLD!"
lower_text = text.lower() # "hello, world!"
print(upper_text)
print(lower_text)"""
"""text = " Python "
stripped_text = text.strip() # "Python"
lstripped_text = text.lstrip() # "Python "
rstripped_text = text.rstrip() # " Python"
print(stripped_text)
print(lstripped_text)
print(rstripped_text)"""
"""sentence = "I like apples, and I like bananas."
new_sentence = sentence.replace("apples", "mango")
# "I love apples, and I love bananas."
print(new_sentence)"""
"""words = ["Hello", "World","hi"]
sentence = " ".join(words) # "Hello World
print(sentence)"""
"""sentence = "Python is easy to learn and Python is versatile."
index = sentence.find("Python") # 0
index = sentence.find("Java") # -1
print(index)"""
"""sentence = "Python is easy to learn and Python is versatile"
index = sentence.count("Python")
print(index)"""
"""text = "Hello, World!"
starts_with_hello = text.startswith("Hello") # True
ends_with_world = text.endswith("World!") # False
print(starts_with_hello)
print(ends_with_world)"""
"""word = "Python123"
is_alpha = word.isalpha() # False (contains digits)
is_digit = word.isdigit() # False (contains letters)
print(is_alpha)
print(is_digit)"""