-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings.py
36 lines (28 loc) · 867 Bytes
/
strings.py
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
#enclosed in either single or double quotation marks
#python does not have a character data type hence characters are considered a string with length of 1
x = "caleb"
print(x)
print(type(x))
#square brackets can be used to access the characters in a sting
#the index starts at 0
print(x[2])
print(x[1:3]) #specifies a range
print(x[0:5])
#other functions and methods
#strip - removes whitespaces at the beginning and end
y = "caleb "
print(y)
y.strip()
print(y)
#len - returns the name of a string
print(len(x))
#lower-- stings to lower case
print(y.lower())
#upper-- stings to upper case
print(y.upper())
#replace - replaces a string with another string
z = "MAYAKA"
print(z.replace("M", "A"))
#Split - divides a a string into substrings
w = "mayaka'caleb"
print(w.split("'")) #divides that the instance of '