Popular Posts

Sunday, August 23, 2020

Python Beginner: Lists

 Hello, developer!


I hope you enjoyed the "Mad Libs Game" in the last post.

Today, we will learn the "Lists" to handle multiple values in lists.


Let's create the first "Lists" as below command.


friends = ["Kevin", "Karen", "Jim"]

friends_property = ["Kevin", 28, "True"]


If you want to modify the list value, you can change it through the below command.


friends[1] = "Mike"


If you want to access the portion of the data in the list, you can do it through the below command.


Calling List values by indexes

friends[0:] : Data from index 0 to all

friends[1:2] : Data from index 1 to 2

friends[1:4] : Data from index 1 to 3(caution! this shows from first number to second number -1) 


I input codes for lists exercise and showed the execution result as the following screenshots.

friends = ["Kevin", "Karen", "Jim", "Oscar", "Toby"]
friends[1] ="Mike"
print(friends[0])
print(friends[1])
print(friends[2])
print(friends[-1])
print(friends[-3])
print(friends[0:])
print(friends[1:3])
print(friends[1:5])
print(friends[0:3])

  

Can you understand the way of creation of the List, update and calling values? If yes, congratulations! 

Now you're an one of the Python List user! See you next post! :)










No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...