-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModifyingstr.py
More file actions
32 lines (23 loc) · 753 Bytes
/
Modifyingstr.py
File metadata and controls
32 lines (23 loc) · 753 Bytes
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
# Modifying strings using uppercase, lowercase, whitespace, replace, split
varstring = "hello, WORLD"
print(varstring)
# Convert to uppercase
print(varstring.upper())
# Convert to lowercase
print(varstring.lower())
# Remove leading and trailing whitespaces (here, no extra whitespace, so no visible change)
print(varstring.strip())
# Replace characters (⚠️ IMPORTANT: you must assign or print directly, as strings are immutable!)
print(varstring.replace("h", "w"))
# Split string at comma
print(varstring.split(","))
# Loop through each character
for x in varstring:
print(x)
# Concatenation of strings
a = "poke"
b = "mon"
print(a + b)
# Formatting float value
num = 8
print(f"HI, the float value conversion from 8 to 8.0: {num:.1f}")