Page 198 - AI Ver 1.0 Class 10
P. 198

Type Conversion
              Type conversion is the process of converting the value of one data type into another data type to match the
              operation required to be performed by the code. Python supports two different types of type conversion.



              Implicit Type Conversion
              When the process of converting the value of one data type into another data type is done automatically without
              involving any action from the programmer is called Implicit Type conversion. Python always converts smaller
              data types to larger data types to avoid the loss of data. For example:




















              Explicit Type Conversion
              Explicit type conversion is also called typecasting because the programmer does the type conversion/casting
              exclusively by changing the data types of the objects using the predefined functions like int(), float(),
              str(),bool() etc. For example:
























              The print() Function
              The print() function is used to display an output on the screen. It converts the expressions into a string
              before writing to the screen. Syntax of the print() function is:

                  print(object(s), sep=separator, end=end)
              Where,

                 • object can be one or more separated by comma and it can be a variable, literal or an expression. An object
                 will be converted to string before printed. It is optional.
                 • sep, if there are more than one objects then it will tell how to separate those objects. Default is space '  '. It
                 is optional.



                        196   Touchpad Artificial Intelligence-X
   193   194   195   196   197   198   199   200   201   202   203