Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 96 - 2629_Devagiri_C-6
P. 96

    float: It represents real number, where a fraction is denoted by a decimal point.
                         For example:
                         a = 7.5

                          string: A sequence of one or more characters enclosed in single or double quotes.
                         For example:

                        a = "hello"
                      In Python, the input() function always returns a value as a string. To use the input as a number,
                      you must convert it into the appropriate data type. This can be done using the following functions:

                          int(): Converts the input value into an integer.
                         For example:
                         a = int(input("Enter a number: "))

                         This code converts the user’s input into an integer before storing it in the variable a.

                          float(): Converts the input value into a floating-point number.
                         For example:
                         b = float(input("Enter a number: "))

                         This code  converts  the user’s  input  into  a floating-point  value before  storing  it  in the
                         variable b.

                             COMMENTS IN PYTHON

                      Comments explain code for users  and  are  ignored  by Python during  execution. They  can  be
                      single-line or multiline.

                      SINGLE-LINE COMMENT
                      A single-line comment is used to add brief notes or explanations to a single line of code. It starts
                      with the hash symbol (#).

                      Syntax of a single-line comment:

                      # This is a single-line comment

                      MULTILINE COMMENT

                      A multiline comment is used when the comment spans more than one line. Python does not have
                      a specific syntax for multiline comments, but you can use either consecutive single-line comments
                      or triple quotes (''' or """) to create a multiline comment.
                      By writing multiple single-line comments one after another:

                      # This is a multiline comment
                      # using single-line comment syntax

                       94
                            Premium Edition-VI

         5

| 91 92 93 94 95 96 97 98 99 100 101 |