Page 438 - AI Ver 3.0 class 10_Flipbook
P. 438
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:
[1]: float(12)
12.0
[2]: int(5.5)
5
[3]: str(12)
'12'
[4]: bool(0)
False
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.
• end it specify what to print at the end. Default is newline ‘\n’. It is optional.
For example:
[1]: print("Good")
Good
[2]: print("Good", "Morning")
Good Morning
[3]: print("Hi!"+"How are you?")
Hi!How are you?
[4]: print("Trends", "Following", sep = "#", end ="!")
Trends#Following!
436 Touchpad Artificial Intelligence (Ver. 3.0)-X

