Python Data Type and Variable

Python Data Type and variable

After some basic of learning python and practice, today we will learn python data type, variable and input.

Python Data Types:

Let us continue mathematical operations from last tutorial

python math

We can perform all kind of mathematical operations in python.

Let us try something different, like 1 + x

python data type

Just like you suspected, we can not do that. maybe we forgot to put the quotation marks.

Let us try again

python data type

Now it is saying the operation isn’t possible because you can not literally add a number to a letter.

It also introduces ‘TypeError’. Yes in python it is called data type.

Let us see what type of data we faced.

To check the data type we will use the ‘type’ function.

We can see we faced int(integer), float and str(string)

Python data type

Let us try something different. Now guess what is the result of type(‘2.5’) or type (‘1’)

data type

So we can see anything we store in between ‘–‘ or “–” will become string and we can perform mathematical operations if the objects are integer or float. There are more types of objects in python like, boolean, tuple, dictionary, list, etc. Also remember we can perform multiplication between a integer and a string. And we can use ‘+’ to add strings.

we love python

If permeable you can change the data type using ‘str()’, ‘int()’, ‘float()’, etc.

type changing

Python Variables:

Like in the mathematics, we can store any object in a variable and later we can call the variable to use. We can use those variables in all kinds of operations just like the original value.

variables and types
variable operations

The value of a variable will not change unless you reassign it to a new value.

We apply str() on a integer
Although it showed us the result we wanted but The value did not change.
Then we reassign the variable using ‘=’ again, and now the variable is changed

Input in Python:

Now we will use the input function to let the user insert a value without changing the script.

Taking the input
Printing the desired result

Remember, input function takes string. Even if we put integer the input function will convert it to string. That is why if we want integer or float value we need to convert it to desired data type.

We also need to let the user know what they are imputing the value for. We will pass a string argument to do that.

input function

20 thoughts on “Python Data Type and Variable”

  1. I got this web site from my friend who informed me about this web
    page and at the moment this time I am visiting this site and reading very informative
    content at this place.

  2. I believe ѡhat you composed made a lot of sense.
    However, what about this? suppose you weге to write a killer post title?
    I mean,I don’t want to tell you how to run your blog, howqever what if you added a headline
    that makes peopⅼe want more? I mean Python Data Type,
    Varіable, and Input – Ɗatalators Blog iѕ a little plain. You ought too glance at Yɑhoo’ѕ home page and note how they create article heɑdⅼines to get viewers
    to click. You might try addіng a video օr а picture оr two too
    gdab readers excitеd about everything’ve written. In my opinion, it might bring your postѕ a littlе

  3. I jսst like the valuable informaqtion you provide оn your articⅼes.

    I will bookmark your blog and test onfe more right here regularly.
    I’m quite sure I’ⅼl be informed many new stuff right right here!
    Good luck for the following!

  4. fantastic issues altogether, you simply received a new reader.
    What might you suggest in regards to your publish that you made a few days in the past?
    Any certain?

  5. What i don’t realize is iff truth be tօld how you aaгe now not actually mucһ more neatly-prеferred than you
    may be now. You’re vеy intеlⅼіgent. You understand therefore
    sіgnificantly in relation tߋ thks matter, made me
    in my opinion imagine iіt from a lot of numerous angles.

    Its like women and men aren’t interested until it’s one tһing
    to do with Womɑn gaga! Your personall stuffs great. Alwas maintain it

  6. Pingback: Google

  7. Pingback: Google

Leave a Comment

Your email address will not be published.