Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 120 - 2609_Logiccode
P. 120

    SEQUENCE
                      A sequence is an ordered collection of items of similar or different data types. The three types of

                      sequence data types are Strings, Lists and Tuples.

                      Strings

                      A string is a sequence of one or more characters put in single quotes, double quotes or triple quotes
                      which are used to represent text-based information. The quotes are not a part of the string.

                      List
                      A list is a collection of data elements separated by comma(,) and enclosed within square brackets.
                      We can also create a list with the same or different data elements.

                      Tuple

                      A tuple is just like a list. It contains a group of elements that can be of different data types. The
                      elements in the tuple are separated by a comma and enclosed in parentheses (). The difference
                      between list and tuple is that list can be modified but tuples cannot be modified after it is created.

                      BOOLEAN

                      Boolean is a data type with two built in values: True or False. They are used for logical evaluation.
                      A True statement returns value 1 while a False statement returns value 0.

                                COMMENTS IN PYTHON

                      Comments in Python can be used to explain parts of the code. It can also be used to hide the code
                      as well. Comments enable us to understand the way a program works. In Python, any statement
                      starting with # symbol is known as a comment. Python does not execute comments. Comments
                      are not a part of the program, but they do enhance the interactivity of the program and make it

                      readable. Python supports two types of comments: Single-line comment and Multi-line comment.

                      SINGLE-LINE COMMENT

                      In case, a user wants to specify a single-line comment, then comment must start with the symbol #.

                      Example:
                        Program:                                         Output:

                        #printing a string                               Hello World
                        print("Hello world")

                      MULTI-LINE COMMENT

                      Python does not have a syntax for multi-line comments. To add a multi-line comment, you could
                      insert a # for each line.

                       118  Premium Edition-VII

| 115 116 117 118 119 120 121 122 123 124 125 |