Page 101 - TP_Play_V2.1_class6
P. 101

Now, the valid value entered is converted into integer value.

                    float(): It is used to change the input value into floating-point value. For example,
                    a = float(input("Enter a number "))
                    Now, the valid value entered is converted into floating-point value.
                 The print() Function

                 The print() function prints or sends the output to the standard output device, which is usually a
                 monitor. This function auto converts the items to strings, i.e., if you try printing a numeric value,
                 the print() function will automatically convert it into equivalent string and print it. The print()
                 function also introduces spaces between items automatically.

                 The general syntax of the print() function is as follows:
                 print (<expression 1> , <expression 2>...)

                 For example:
                 print ("Python is easy").

                 Let's create a program to use the input( ) and print( ) functions.
                       Program.py
                    File  Edit  Format   Run   Options   Window    Help

                    #Program to use the input( ) and
                                                                                  Output
                    print( ) functions.
                    age = input ("Enter your age:")                            Enter your age: 12
                    name = input ("Enter your name: ")                         Enter your name: Ankit
                    print (name, "your age is," age)                           Ankit your age is 12




                                                    Using input() and print() functions
                    VARIABLES IN PYTHON

                 Variables are memory reference points where we store values which 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 variable because Python is a dynamically typed language and it identifies the
                 variable type automatically. Let’s understand this with the help of the given examples.
                     name = "John"  # name variable is of type str
                     age = 10 # age variable is of type num

                     print(name)
                     print(age)
                 Declaring and Initializing a Variable

                 In Python, variables are declared and initialized at the same time in the following way:

                   a = 10
                   b = 20
                   print ("a=", a)
                   print ("b=", b)


                                                                        Introduction to Programming Python        99
   96   97   98   99   100   101   102   103   104   105   106