Page 98 - 2403_Trackpad_V5.1_C6_Fb
P. 98

Example:
                  >>> name = input("Enter your name: ")
                      Enter your name: Trackpad
                  We will learn about variables later in this chapter.
                  By default, Python considers the input value as string even if you entered a number. You cannot
                  perform calculation on string. To perform calculations, you need to convert the string into integer
                  or floating-point value.
                  To do so, Python provides following functions:
                     int(): It is used to convert the valid input value into integer. For example,
                      a = int(input("Enter a number "))
                      Now, the entered value is converted into integer value.
                     float(): It is used to convert the valid input value into floating-point value. For example,

                     a = float(input("Enter a number "))
                      Now, the entered value is converted into floating-point value.

                  THE print() FUNCTION

                  We use the print() function to display the result on the screen. The content is written within the
                  parenthesis. To get the output, follow the given steps:
                  Step  1   Open the Python Shell window.
                  Step  2    In front of the command prompt, type print("Hello Students") and press the Enter key.
                            Do not forget to include the double quotes (" ").

                  Step  3   The output is displayed in the next line in the same Python Shell window.












                  We use comma to print multiple texts in a single print( ) function. For example,

                  print("Hello,", "My Name is Amit.", "I am 11 years old.")




                       Tick ( ) if you know this.
                       ▶   Python is an interpreted language that executes code line by line.

                       ▶  The Python Shell window executes one command at a time.




                            VARIABLES IN PYTHON

                  A variable is the name of the memory location that is used to store data values that can be
                  accessed or changed later. The names given to the variables are known as identifiers. In Python,
                  we do not need to specify the type of a variable because Python is a dynamically typed language
                  and it identifies the type of a value automatically.


                   96   Premium Edition-VI
   93   94   95   96   97   98   99   100   101   102   103