In lesson, we will focus on Python list of strings. In python lists we can list and python data structures. Here, we will see one of them, Python list of strings. Then, let’s give example of these string lists to understand better these types of lists in python.
First of all, let’s show basic string list in python with an example.
You can also learn how to Sort a Python list
In this string list, we have 4 members and all of them are string. The output of this python string will be like below:
If we use python len() function for this python string list, we will see 4 as a return.
Now, let’s use an important python function that we use with Python list of strings. This is python sort() function. Here, we will sort out python string list as ascending (A to Z). So, we will not use any parameter with sort () function.
As you can see below, our python string list is sorted as ascending (A to Z).
Now, let’s do this sorting as descending (Z to A). For this purpose, we will use reverse parameter and we will set it as True. In the previous exaample we did not use this parameter and by default iit is accepted as False.
Here, our string is sorted as descending (Z to A).
We can also modify the members of Python list of strings. We can change all the members as uppercase, lowercase or we can capitalize each member in the list. Let’s give examples for these functiions that are used with Python list of strings.
Below firstly, we will convert all the members of python string list to lower case firtly. Then we will convert all memebrs to upper case. Lastly, we will convert another list that has members consist of all lower cases and we will capitalize it. In other words all the members of the list will start with an upper case again.
Leave a Reply