19 May Python Variables
Variables in Python are reserved memory locations and do not work like variables in Java, or C. They aren’t declared in the same way. You only need to assign a value in Python, for variable declaration and that’s it! In this lesson, we will learn about Python Variables.
Here are some examples,
The = is used to assign a value to a variable. Here we have 3 variables, va1, val2 and val3,
1 2 3 4 5 6 7 8 9 |
val1 = 6; val2 = 10; #sum val3 = val1 + val2; print val3; |
Let us compare Java with Python for the same example. In Java, you need to follow a lengthy process of using datatype,
1 2 3 4 5 6 7 8 9 |
int a = 10; float b = 3.5; int sum = 0; // sum sum = a + b; System.out.println(“Output: ”,+sum); |
Let us now see an example of integer and float assignment in Python,
1 2 3 4 5 6 7 8 9 10 |
score = 70 player = "Jacob" # integer print (score) # string print (player) |
The following is the output,
In this lesson, we learned how to work with Variables in Python.
Video Tutorial (English)
Video Tutorial (Hindi)
If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.
For Videos, Join Our YouTube Channel: Join Now
Recommended Posts
No Comments