forked from shannonturner/python-lessons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_lower.py
38 lines (22 loc) · 949 Bytes
/
string_lower.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
37
38
# String methods: string.lower()
# string.lower() is used for turning all characters in your string lowercase.
# There are some related string methods too, like string.upper()
name = "SHANNON!!"
print name.lower() # shannon!!
print name # it's back to the original of SHANNON!!
# To make the changes stick:
name = name.lower()
print name # shannon!!
# string.upper() will turn all characters in your string uppercase but otherwise works in the same manner as string.lower()
greeting = "hello, hi" # not very exuberant ...
print greeting.upper() # MUCH BETTER!
# Making the changes stick:
greeting = greeting.upper()
print greeting # HELLO, hi
# string.lower() and .upper() are primarily used for testing strings in a case-insensitive manner
gender = 'F'
if gender.lower() == 'f':
print "Hi lady!"
# To accomplish the same thing without string.lower(), you would have to do:
if gender == 'F' or gender == 'f':
print "Hi lady!"