Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 93 - 2615_KEC
P. 93

    DATA TYPES IN PYTHON

                     A data type is used to define the type of value a variable can contain. For example, a person’s
                     name must be stored as a string value whereas the person’s age must be stored as an integer.
                     Commonly used data types in Python are:

                       int: Positive or negative whole numbers (without any fractions), for example: a = 3
                       float: Any real number in which a fraction is denoted by a decimal symbol, for example: a = 3.5

                       string: A collection of one or more characters put in single or double-quotes, for example: a=”hello”

                               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. Python does not execute comments.
                     Comments are not a part of the program, but they do enhance the interactivity of the program
                     and make them readable. Python supports two types of comments: Single-line-comments and
                     multiline comments.

                     Single-line Comment
                     Python uses the hash (#) symbol for writing single-line comments.

                     Example:
                     Program:  #printing a string

                                print("Hello TrackPad")
                     Output: Hello TrackPad

                     Multiple-line Comment

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

                     Program: #print three names
                                print("Roli")

                                print("Proloy")
                                print("Devansh")

                     Output: Roli Proloy Devansh
                     However, the text written inside triple quotes (''' or " " ") is also considered a comment. You can
                     use the triple quotes to write multiline comments. For example:
                     '''

                     This is a multiple-line comment that spans two lines in Python.

                     '''

                                                                                                 Introduction to Python  91

| 88 89 90 91 92 93 94 95 96 97 98 |