Page 437 - CITS - Computer Software Application -TT
P. 437

COMPUTER SOFTWARE APPLICATION - CITS




           1  #Using single quotes
           2  str1 = ‘Hello Python’
           3  print(str1)
           4  #Using double quotes
           5  str2 = “Hello Python”

           6  print(str2)
           7
           8  #Using triple quotes
           9  str3 = ‘’’’’Triple quotes are generally used for

           10 represent the multiline or
           11 docstring’’’
           12 print(str3)

           Output:
           Hello Python
           Hello Python
           Triple quotes are generally used for represent the multiline or docstring.

           Python List

           In Python, the sequence of various data types is stored in a list. A list is a collection of different kinds of values or
           items. Since Python lists are mutable, we can change their elements after forming. The comma (,) and the square
           brackets [enclose the List’s items] serve as separators.
           Although six Python data types can hold sequences, the List is the most common and reliable form. A list, a
           type of sequence data, is used to store the collection of data. Tuples and Strings are two similar data formats for
           sequences.
           Lists written in Python are identical to dynamically scaled arrays defined in other languages, such as Array List in
           Java and Vector in C++. A list is a collection of items separated by commas and denoted by the symbol [].
           List Declaration
           Code
           1  # a simple list

           2  list1 = [1, 2, “Python”, “Program”, 15.9]
           3  list2 = [“Amy”, “Ryan”, “Henry”, “Emma”]
           4
           5  # printing the list
           6  print(list1)
           7  print(list2)

           8
           9  # printing the type of list
           10 print(type(list1))
           11 print(type(list2))








                                                           424

                             CITS : IT&ITES - Computer Software Application - Lesson 120 - 137
   432   433   434   435   436   437   438   439   440   441   442