Using type() method

Using type() method

Lesson Details:
September 17, 2020

Video Transcription: In this lecture I'm going to tell you about a very special method of Python which is type this video is brought to you by Appy Pie’s Academy, so type method comes in handy when while determining the datatype of a particular identifier so we can use the type method whenever we are interested in knowing we are in the requirement of knowing the datatype of a particular identifier here by identifier I mean to say variable okay so what I will do is as an example let me take some variables like I have taken this variable code and I have assigned it the value integer value 9 double 0 9 then I am going to take another variable amount and I'm going to give it a float data type value which is also called floating point data type okay so another variable is name value of which is our Anand mahajan within double quotes of course it is a string and then I have taken a bool data type variable flag and I have assigned it true because true has been assigned to the variable flag naturally its type would be boolean which is called boot print then I'm going for these print statements print type within parentheses code print type within parentheses amount print type within parentheses name so all these are variables print type within parentheses the variable flag okay so let's execute the program what will happen is it is going to print the data type of all these variables okay so this is the output as you can see hmm within angular brackets writing class means cat a type so her hair class means data type int was displayed for code float was displayed for amount because amount had a floating point value and STR is stands for strain this is being printed for the variable name because it was containing this variable was containing a spring strain data type value and finally it is printing class bore means data type bool for the variable flag why because flag variable was containing a boolean data type value so it happened to be a bool variable so data type was born so bool is getting printed for the variable flag. 

loader
Course content