Variables are letters or set of letters or combination of letters or numbers that store some value.
For Example:
a = 10
bcde = "The author of this website is Yash Vardhan"
c123 = True
d = None
e = 0.88
Now, in this example,
- a stores a number or integer that is 10
- bcde stores a string that is The author of this website is Yash Vardhan
- c123 stores a boolean which is True.
- d stores none which means nothing
- e stores a floating point number which is 0.88
Integers are simple numbers without decimal. These can be positive or negative. Eg:
1, 2, 3, 4, 5, 6, 9, 10, -1, -2, -3, -100, etc.
String is anything which is written in single, double or triple quotes. In previous chapter, we learnt that triple quotes are used to make multi-lined comments but it is valid till it is not under any variable. The minute it comes under the variable, it becomes a string.
Boolean is the value in which the situation is either true or false, it can't be half true and half false. Boolean is the true and false value.
None means nothing so if we will give any variable a value none then it means nothing.
Floating point numbers are decimal numbers which have a decimal. They can be either positive or negative. Examples:
1.09, 0.88, 0.66, 1.0876836, -0.72563, -1.928, etc.
DATATYPES
A datatype is the type of data that we are storing in the variable. Let's split this word datatype in two words, data and type. It means the type of data that we are storing in the variable.
Datatypes are of 5 types:
- Integers
- Strings
- Booleans
- None
- Floating Point Numbers
We discussed these words in the VARIABLES part of this chapter.
CHECKING THE DATATYPE OF DATA STORED IN A VARIABLE
To check the datatype of data stored in a variable, we need to have a variable. Let's create a variable.
a = 18
I created a variable named a and specified a value 18. Now, how we will check the type of this data. To check the type of the data specified in the variable a, we will use a function named type. to use this function we are going to write print command and then type and are variable's name.
CODE
print(type(a))
Here, print is the command that we learnt in the last chapter and type is the new function that we talked about and a is the variable that we created.
Note : If you have created the variable with some other name then give that name.
OUTPUT
With this our second lesson is over.
1 Comments
Very Nice posts and awesome website.
ReplyDelete