Python variables in Python Programming

Python variables in Python Programming

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.

speed_of_light= ("23465394")
print (speed_of_light)      #speed of light in meter per second
OUTPUT: 23465394

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)     
print (light)
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 
print (light) 
Output:
23465394
1407923640

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.

Example:

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
print (minute)
Output: 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]

 

Add a Comment

Your email address will not be published. Required fields are marked *