Tech Blogs

Tech Blogs

A gentle introduction to python

A gentle introduction to python

Lists and more

Welcome all ,In the previous article we have given an introduction to python where we have discussed about the python data types ,variables and strings. You can find it here

In this article we are going to discuss about lists and many more so let's start


Lists are very similar to arrays. arrays are like the shelf in a room . As you can place many items in a row of shelf of same type for better organisation same way array are like series of container where you will store many values of same datatypes
Here is an example on how to build list

mylist =[]
mylist.append(1) //adds 1 to  end to the end of the list
mylist.append(2) //adds 2 to end of the list
mylist.append(3) // adds 3 to end of the list
print(mylist) //prints out list

Arithmetic Operators

using operators with numbers

just as any other programming languages, addition,multiplication,division,subtraction operators can be used with the numbers

print(1+3) //adds 1+3
print(2 * 3) //multiplies 2 with 3
print(2//3) //Does the floor division between the numbers
print(2%3) //Prints out the remainder by dividing the two numbers

using Operators with strings

As we have seen the operators with numbers It's time to see how some of the operators works with strings which are nothing but the stream of characters

  • Python supports concatenating(i.e joining the two strings in simple worlds) strings using the addition operators
    helloworld = "hello"+ " "+"world"
    print(helloworld) //prints out hello world
  • Python also supports multiplying strings to form a string with a repeating sequence
    tenhellos = "hello"*10
    print(tenhellos) //prints hello ten times

    Using operators with lists

  • Lists can be joined with the addition operators
    evennumbers = [2,4,6,8]
    oddnumbers = [1,3,5,7]
  • using multiplication operator to form new list with repeating sequence


As we discussed a lot in this article finally it's exercise time !!

  • The target of this exercise is to write all the above discussed code in a code editor and playing around with it
  • Take ten examples of your choice run it to see the results and share the output in comments

That's it for this Article .In this Article we discussed a brief about python lists and it's operations . I hope these articles are helping you learn python , so consider to like and give feed back.🙂

Share this