- Make all the characters in a string upper case
- Make all the characters in a string lower case
- Make the first letter of a string capital
- Make a string title case
- Check if a string is a number
- Check the length of a string
- Pad a string with zeros
Python gives us many useful methods for dealing with Strings.
1) Make all the characters in a string upper case
#Make all letters in a string upper case
mystring = "to be or not to be"
print(mystring.upper())

2) Make all the characters in a string lower case
#Make all characters in a string lower case
mystring = "THAT IS THE QUESTION"
print(mystring.lower())

3) Make the first letter of a string capital
#Make first character of a string upper case
mystring = "whether 'tis nobler in the mind to suffer"
print(mystring.capitalize())

4) Make a string title case
Title case means that the first letter of every word is capitalized
#Use Title case. First character of every word capital.
mystring = "to kill a mockingbird"
print(mystring.title())

5) Check if a string is a number
#Check if a string is a number
mystring = "1212312"
print(mystring.isnumeric())

6) Check the length of a string
#check the length of a string
mystring = "To be, or not to be, that is the question"
print(len(mystring))

7) Pad a string with zeros
id_1 = "12121"
id_2 = "434"
#pads the left side of a string to equal the specified length.
print(id_1.zfill(8))
print(id_2.zfill(8))

- Python Lesson 1: Hello World in Python
- Python Lesson 2: Reserved Keywords
- Python Lesson 3: Creating Variables
- Python Lesson 4: Performing math calculations in Python using operators
- Python Lesson 5: Working with Strings
- Python Lesson 6: Useful String Methods
- Python Lesson 7: Getting User Keyboard input
- Python Lesson 8: Importing Modules into your Python code
- Python Lesson 9: Decision making in Python
- Python Lesson 10: Creating loops in Python
- Python Lesson 11: Lists in Python
- Python Lesson 12: Tuples in Python
- Python Lesson 13: Dictionaries in Python
- Python Lesson 14: Sets in Python
- Python Lesson 15: Dealing with dates and time
- Python Lesson 16: Creating and using functions
- Python Lesson 17: Creating and using classes in Python
- Python Lesson 18: List Comprehensions
- Python Lesson 19: Lambda Functions
- Python Lesson 20: Error Handling