Learning Python - Part 4 - Introducing Lists

Untitled-1-Recovered.jpg
Learning Python - Part 3 - Comments

Learning Python - Part 2 - Declaring Variables and understanding strings

Learning Python - Part 1 - Familiarise yourself with the Python Console and write your first Python program!
https://steemit.com/steemiteducation/@pentest1002/learning-python-part-3-comments https://steemit.com/programming/@pentest1002/learning-python-part-2-declaring-variables-and-understanding-strings https://steemit.com/programming/@pentest1002/learning-python-part-1-familiarise-yourself-with-the-python-console-and-write-your-first-python-program

<p dir="auto"><h1><strong>Introducing Lists<br /> A list is a collection of items in a particular order. You can make a list that includes the letters of the alphabet, the digits from 0–9, or the names of all the people in your family. You can put anything you want into a list, and the items in your list don’t have to be related in any particular way.<br /> In Python, square brackets ([]) indicate a list, and individual elements<br /> in the list are separated by commas.<p> <p dir="auto">For example: <pre><code>names = ['james', 'connor', 'jacob', 'bella']<br />print(names)<br /> <p dir="auto">The output will be: <pre><code>['james', 'connor', 'jacob', 'bella'] <p dir="auto"><h1><strong>Accessing Elements in a List<br /> Lists are ordered collections, so you can access any element in a list by<br /> telling Python the position, or index, of the item desired.<p> <pre><code> names = ['james', 'connor', 'jacob', 'bella']<br />print(name[0])<br /> The output will be: <pre><code>james Lists start from 0, so james is 0, connor is 1, jacob is 2, bella is 3. <p dir="auto">You can also use strings methods on lists, for example: <pre><code>names = ['james', 'connor', 'jacob', 'bella']<br />print(names[0].title())<br /> The output will be: <pre><code>James <p dir="auto">Python has a special syntax for accessing the last item. <pre><code>names = ['james', 'connor', 'jacob', 'bella']<br />print(names[-1])<br /> The result will be the following: <pre><code>bella <p dir="auto"><br />If this post helped you, don't forget to upvote and comment if you have a question! <p dir="auto">See you in the next Post!