Day 4; Basic Python Collections(Python 30 Day challenge)

1. Lists

Lists are created by having characters inside square brackets, separated by commas, with each value inside quotation marks
The code below also shows how to access items within a list

Adding items to a list

usin…


This content originally appeared on DEV Community and was authored by ourjulybeauty

1. Lists

Lists are created by having characters inside square brackets, separated by commas, with each value inside quotation marks
The code below also shows how to access items within a list
Lists and how to access them

Adding items to a list

using the .append() method

adding items to a list using the append method

using the + operator

adding items to a list using the + operator

using the .extend() method

adding items to a list using the extend method

using the .insert() method

adding items to a list using the insert method

Removing items from a list

using the .remove() method

Image description

using the del

Image description

using the .pop() method

Image description

using the .clear() method

Image description

2. Tuples

Tuples are immutable i.e once created they cannot be changed
But they can be nested inside lists, where they are easily accessible using their index
Image description

2. Exercise day 4 code

Image description


This content originally appeared on DEV Community and was authored by ourjulybeauty


Print Share Comment Cite Upload Translate Updates
APA

ourjulybeauty | Sciencx (2021-11-14T09:00:32+00:00) Day 4; Basic Python Collections(Python 30 Day challenge). Retrieved from https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/

MLA
" » Day 4; Basic Python Collections(Python 30 Day challenge)." ourjulybeauty | Sciencx - Sunday November 14, 2021, https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/
HARVARD
ourjulybeauty | Sciencx Sunday November 14, 2021 » Day 4; Basic Python Collections(Python 30 Day challenge)., viewed ,<https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/>
VANCOUVER
ourjulybeauty | Sciencx - » Day 4; Basic Python Collections(Python 30 Day challenge). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/
CHICAGO
" » Day 4; Basic Python Collections(Python 30 Day challenge)." ourjulybeauty | Sciencx - Accessed . https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/
IEEE
" » Day 4; Basic Python Collections(Python 30 Day challenge)." ourjulybeauty | Sciencx [Online]. Available: https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/. [Accessed: ]
rf:citation
» Day 4; Basic Python Collections(Python 30 Day challenge) | ourjulybeauty | Sciencx | https://www.scien.cx/2021/11/14/day-4-basic-python-collectionspython-30-day-challenge/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.