Methods
In this practice, you´ll learn some methods to modify a string
In this case, to use the string methods we´ll have to call them in this way
. + method name + ()
The methods that in this practice are going to be reviewed are
.capitalize()
Converts the first character of the string in uppercase
.upper()
Converts the whole string in uppercase
.lower()
Converts the whole string in lowercase
.title()
Capitalizes the first letter of every word of the string in
For example:
x = "hello"
print(x.upper())
Exercises
Try printing different types of strings using the previously mentioned methods
Try printing variables with methods and use methods inside printing statements
Concatenation
Concatenating strings and different types of data in Python is used for many things such as combining variables with immovable text
For example
x = "Costa Rica"
print("I love " + x)
Exercises
Try different types of values on variables
Try concatenating with different methods
Solution of Exercise number 2
x = "abraham lincoln"
y = "uNiTed sTatEs"
print(x.title() + " was president of the " + y.title())
Commentaires