During this lecture, we are going to discuss the Python variables with more details. Are you want to know about Variable then you can also read my previous lecture. We have discussed in the previous lecture about “Python print variable and Python data types in Python 3”. In this lecture, you are going to learn how to use the correct data type of variables to compute the correct result in python programming. If we will use the wrong Data type then computed result will be wrong.
How to use Correct Python variables in Python Programming?
Example of Data Types
Like we initialize a Python Variables variable in string Datatype.
print (speed_of_light)Â Â Â Â Â #speed of light in meter per second
We will convert it in meter per minute.
If we can multiply direct this variable by (speed_of_light * 60). It will be wrong because string keyword will repeat 60 times as given below.
light = (speed_of light*60)Â Â Â
Output: 23465394234653942346539423465394234653942346539423465394234653942346539423465394... repeat 60 times
that is wrong output because we used wrong Data Type. if we can multiply any number by string then string alphabets will be repeated.
Now we will use the correct Python Variables data type
we will convert it in meter per minute by multiplies 60 using correct Python variable’s Data Type.
speed_of_light =Â 23465394
print (speed_of_light)Â # also speed of light in meter per second
light = (speed_of_light*60) # it is correct because it is possible to multiply integer with integer
Correct Output âˆš because we have to use an integer data type that is correct according to the program logic. Thatâ€™s why itâ€™s much important to know about it data types and it’s used in the program.
How to use Multiple Python Variables with the Same Name in Python Programming?
We can useÂ multiple variables with the same name in a program.
minute = 6Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â # Declare a minute variable
minute = (minute+1)Â Â Â Â Â Â #Now minuteâ€™s variable value will be 7
minute =(minute*2)Â Â Â Â Â Â Â #Now minuteâ€™s variable value will be 14
Note: Compiler start computes the value from topÂ to bottom and Print those value which is given at the end before print statements. As you can see in the above example. I hope you are understanding the concept of value at each given line. In this lecture, we learn about â€œPython variables in Python Programming â€.
[mks_pullquote align=”left” width=”848″ size=”15″ bg_color=”#8ed65c” txt_color=”#ffffff”]I hope this series will be very helpful to understand every concept of Python Programming. You can also learn about What is WordPress?, the Difference between Web Design and Web Development and many another programming languages.Â Special for the beginner who wants to learn from scratch. It is a convenience for all the students to make notes. You can also watchÂ the videoÂ lecture, practice through the written article of every Specific lecture. If you have any queries about any lecture please discuss in the comments section. Don’t forget to give your feedback. Thank you!.[/mks_pullquote]