Page 441 - ComputerScience_Class_11
P. 441

These are the main types of sequence data types available in Python.
                 •  String                   •  List                    •  Tuple


                 12.4.1 String
                 A string is a sequence data type in Python that stores a group of characters enclosed in single (' ') or double (" ") quotes.
                 A string in Python is an immutable sequence of characters enclosed in quotes. It is used to represent text such as
                 names, messages, sentences or any combination of letters, numbers and symbols.
                 Syntax of strings are as follows:

                 variable_name = "text"
                 Program 5: To store data in a variable using the string sequence data type.
                     Program 5.py
                  File  Edit  Format   Run   Options   Window     Help


                  # Assigning a string value to variable name
                  name = "Shivam"
                  # Printing the name
                  print("My name is", name)
                  # Assigning a string value to variable  school
                  school = "Green Valley School"
                  # Printing the school name
                  print("School Name:", school)




                     Output

                  My name is Shivam
                  School Name: Green Valley School




                 12.4.2 List
                 A list is a sequence data type in Python that stores multiple values in an ordered manner. The elements of a list are
                 enclosed in square brackets [ ] and separated by commas. Each element has an index number starting from 0. A list
                 is mutable, which means its elements can be modified after it is created. Therefore, it is considered a dynamic data
                 structure because its contents can be changed.
                 Syntax of list is as follows:

                 list_name = [element1, element2, element3, ...]
                 Program 6: To store data in a variable using the list sequence data type.
                     Program 6.py

                  File  Edit  Format   Run   Options   Window     Help

                  # Creating a list of fruits
                  Fruits = ["Apple", "Banana", "Mango", "Grapes", "Orange"]
                  # Printing the list
                  print("The items in Fruits are:", Fruits)







                                                                                               Data Types in Python  439
   436   437   438   439   440   441   442   443   444   445   446