-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrings.py
More file actions
35 lines (29 loc) · 917 Bytes
/
strings.py
File metadata and controls
35 lines (29 loc) · 917 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
33
34
35
long_string = "I'll catch you if you fall - The Floor"
sub_string = long_string[:4]
print(sub_string)
print(type(sub_string))
print(long_string[-5:])
print(long_string[:-12])
if "Floor" in long_string:
print("Floor found!")
print(long_string[:4] + " be there")
print("%c is my %s letter and my number %d number is %.5f" %
('X', "favorite", 1, 3.14))
print(long_string.capitalize())
print(long_string.find("Floor"))
print(long_string.isalpha())
print(long_string.isalnum())
print(len(long_string))
print(long_string.replace("Floor", "Ground"))
print(long_string.strip())
quote_list = long_string.split(" ")
print(quote_list)
# Concatenating strings :
names = ["raymond", "rachel", "matthew", "roger", "betty", "melissa", "judith", "charlie"]
# Don't do it like this :
s = names[0]
for name in names[1:]:
s += ", " + name
print(s)
# Do it like this instead, always use join()
print(", ".join(names))