what are python sequences and its operations.


A sequence is a group of individual items.  We can insert values in an order and we get the result in sequence.


python consists of six types of sequences

  1. Python strings
  2. python lists
  3. Python Tuples
  4. Byte Sequences
  5. Bytes Arrays
  6.  Range() Objects

1. Python Strings

Generally a string is nothing but a group of characters. In Python for creating an array of characters we use strings. For creating a string in python we use single or double quotes.

  for example


  For creating an empty string in python


  We can also create string like


   In order to know the type of variable we can use ‘type’

    for example


   it displays

     <class ‘str’>   # it tells the name variable is of ‘string’ type

2. Python Lists

    List is a collection of ordered group of items. For declaring a list in python we have to use Square brackets [ ]. Python lists can hold any kind of data.



   For accessing list items we can use index



  In order to access part of list elements we can use slice



    output will be


3. Python Tuples

    Tuples are also similar like lists but they are immutables, which means tuples cannot be modified. The values inside the tuples cannot be changed once declared. For declaring python tuples we have to use parenthesis (). Tuples can also hold different kinds of data.



    Tuple cannot be modified so if we try to modify the element in python it shows error

         tuple1[0]=’milk’  //it shows error

    For accessing elements in the tuple

         tuple1[0]    //output will be (‘rice’)



       output will be


4. Bytes Sequence

    bytes() returns an immutable bytes object.  In order to display we use bytes(5) it displays b’\x01\x02\x03\x04\x05′.

Bytes() is an immutable so if we try the change an item it will display an error. so we can’t modify a bytes() object.

   Bytes Arrays

       It is like a bytes obect but it can be modified since it is mutable.



     it displays bytearray(b’\x00\x00\x00\x00′)


          it displays bytearray(b’\x01\x02\x03\x04\x05′)

5.  Python range() objects 

    A range() object  gives a list of numbers.


   for i in range(0,5)





learn more from about python 


Operations with Python Sequences

  • Concatenation
  • Integer Multiplication
  • Python Slice
  • Membership


1. Concatenation

        It is used to add the second one to first one



       Output will be



2. Integer Multiplication

         We can replicate a string for several times


          india * 5



3. Python Slice

      If we want a part of a sequence we can used slice



    output will be

‘      ame’

  1. Python Membership

To check whether the value is present in a sequence or not. We used ‘in’ Operator


‘ind’ in ‘india today’

output will be



To learn more about  python click here


Advantages of Python