Getting More On Variables

Getting More On Variables

Welcome Again guys to PythonInsta. After a long time I am creating another Tutorial. In this tutorial, we are going to learn more about variables and some methods that we can use on them. So, without further ado, let's start 👉

Coming Up Next ⇒




So, In The previous lesson, we learned about variables and how to create them. This time we are going to do some fun things with them.

The type() Function

So,type() is a function used to tell which type of Data type(I will explain Data Type in my next Tutorial) is stored in the variable. For example.


So, here you found that when I wrote a string(alphabets) in the variable x, It showed class str which meant that the value that is stored in the variable is an str(string).
Likewise, in the variable y, it showed me, class int(integer) and in variable z, it showed me, class float(decimals).

Correct Way To Write Strings

So, you might be thinking whether should I use single quotes, or double quotes, well the answer is both.



Rules Of Variables

  • They Are Case-Sensitive. This means that <a> and <A> are different variable names.
  • They can be overwritten if you again give them a different value to the same variable.
  • Variable names should only start with a letter or underscore(_). It should never start with a number.
  • Variable names should only contain alpha-numeric characters(A-Z, a-z, 0-9, and _)
 
Let's see →


Assigning values to multiple variables at once

So, there is some cool about Python, It's utility is the purrfect.
You can assign values to multiple variables in a single line:


Just make sure that after the quotes(""), Don't forget to put the comma(,). And yeah, The number of values should be equal to the number of variables, Or you are gonna get kaboomed :/

Conclusion

Okay, So in this tutorial you learnt more about Variables. You learnt-
  • How to get the data type of Variables using type() function
  • Rules of Variable names
  • Assign values to multiple variables at once
So, that's all for today. In the next tutorial, we are gonna be learning about Numbers and Casting.

End Of Tutorial.....

Hope you liked this tutorial.

Don't forget to Follow, Like, and Comment on my Social Pages ➤ Twitter ➤ Instagram ➤ Facebook

Thanks,

Dheeraj


Comments