Python Programming Tutorial for Beginners - Section 2: Variables
FREE PYTHON E-BOOK: http://srepythonprogramming.instapage.com/
Get our 4 hour online Python programming course FREE for life with the link below:
http://stoneriverelearning.com/courses/python-programming-for-beginners?product_id=12227&coupon_code=YTPYFREE
In this Python Programming tutorial video we will be discussing about variables and their function in Python programming.

Hello and welcome to Part 4 of the Basic Python 3 Tutorial Series. This video is going to be covering 'variables' in Python 3. Very quickly, you find yourself using variables pretty much in every single program. Variables act as a sort of placeholder for whatever you want to place in them and variables can be changed, so that is, hence, the name 'variable'. Another big important use for variables is to not have to hardcode data too often.

So, say you have a forum or something like that and you want to print out usernames or show usernames each time someone posts. Instead of hardcoding the username each time, so you've got 15 posts, instead of having it hardcoded in as in print user number one each time it needs to print out user number one, what happens when user number one wants to change their name? Would it be easier for you to go in and edit the 15 iterations of the string user number one? Or would it better if you had a variable called 'username' and you just change that one variable username, and then at all the prints, they will just print username? Well, it would be definitely easier just to make that one simple edit. And so that's another reason why variables are extremely popular to be used and they're definitely a very important aspect to programming.

So let's go ahead and show some examples. So, we defined a variable is very simple. It's just some text. So we can say exVar (for example Var) and it can be equal to anything. Let's say it's equal to 100. What we can do then is we can print (exVar). Like that. And now we're ready to run this program. So save it and run it. And the output is 100 for example variable 100.

Now, that's not everything that we can do. We can also do strings in our variables. So we could say, instead of 100 as an integer, we could say it's a string. Save and run that. Let's print (exVar). Save and run that. 100 again.

Now, variables can contain all sorts of things. They can contain integers, floats, strings. You could put in functions in there. You could put in other data structures that we've not even talked about, like lists and dictionaries. All kinds of things.

We can also have operations within our variables. So, we could do something like this. We could say opVar (for operation variable) equals, and let's change exVar to an integer again, so 100, it's going to equal exVar divided by 5.3. So, this variable equals exVar, so this variable here, divided by 5.3. So what's nice about this is we can already see where we have maybe used exVar already twice, right? We want to output exVar and then we also want to go ahead and do some operation with exVar. So we've already got two iterations of exVar already. And this is an extremely simple program. So as time goes on, you can see how extremely valuable variables can become. So let's go ahead and first let's print this. So print (opVar), and we get our answer, 100 divided by 5.3 is 18.8679 and so on. So, here we can do operations as well.

So what are the limitations of variables? Well, we can call them just about anything we want, but we cannot start a variable with a number. So we couldn't say 1var equals 5. We wouldn't be able to do that. It's going to give us 'Invalid Syntax'.

Now, sometimes you might want to have a number in the beginning of a variable. And the example I come across sometimes is let's say I'm making a moving average for a data set. I want to be able to do 100ma for 100 moving average. I can't do that. But, what you can do if you desperately just want that beginning to be a number, you can do basically an underscore (_) here. And so, it's great to do that, and there's no problem. We can run that. And then later on we can print this. So, we could say, print (_100ma). Save and run it. Now, we can get away with that as well.

So that's going to conclude the 'variables' tutorial. The next video is going to be covering the 'while loop'. So stay tuned for the next chapter. Thanks for watching.


Python Programming Tutorial for Beginners - Section 1: Installation
https://goo.gl/cprtUd

Python Programming Tutorial for Beginners - Section 1: Print and Strings
https://goo.gl/UtrHCw

Python Programming Tutorial for Beginners - Section 1: Math
https://goo.gl/cXv9mX

Check us out on social media:
https://www.facebook.com/srlearning
http://www.linkedin.com/profile/view?id2456030
https://plus.google.com/110612691231949136380/po...
https://twitter.com/sr_elearning