Viewers: in countries Watching now:
Due to its power, simplicity, and complete object model, Python has become the scripting language of choice for many large organizations, including Google, Yahoo, and IBM. In Python 3 Essential Training, Bill Weinman demonstrates how to use Python 3 to create well-designed scripts and maintain existing projects. This course covers the basics of the language syntax and usage, as well as advanced features such as objects, generators, and exceptions. Example projects include a normalized database interface and a complete working CRUD application. Exercise files accompany the course.
Assignments in Python are handled with the assignment operator, which is the Equal sign. Let's go ahead and make a working copy of syntax.py. I'll call it syntax-working.py. And we'll open that working copy, and we'll go ahead and create an assignment. So I'll have a variable called a, and I will assign it the value 1. Now what this does in Python is it actually defines the variable a, and it creates an integer type variable, and it puts the value 1 in it.
And so in the print statement, I can print a. And if I go ahead and save this and run it, we'll see that we get the value 1 printed. If instead I were to put a string there, say "one" spelled out, run that then we get a one here. We can look at the type of the variable that was created by using the type function. And so this will print the type and the value.
Save that and run it.
See that that's a Class String, it's the type.
In fact everything in Python is an object, and objects have classes, and so the
type of a thing is typically the name of the class.
And so if I make this a number again and save that and run it, we'll see that we
get a variable of the
And it creates it of the appropriate type, or the appropriate class. You can assign multiple objects at the same time. You can say a, b = 0, 1, and then if I print(a, b), then I'll get both of those values, the 0 and the 1. Interestingly, you can even do something like this, where you're actually swapping these values.
You can use the same variables on the right and the left-hand side of the Equal sign, and you can pretty much do this safely under most circumstances. So here we'll get a 1 and 0 when we run this, 1, 0. There are some types of objects in Python that are sets of values, or sequences of values, called lists, and tuples, and things like that. For example, if we say a = (1, 2, 3, 4, 5), by putting them in the parentheses, this makes this into a tuple.
And if we save this and run it, you see that we get all of those values. Now, when you use print on an aggregate type, on a set, or a tuple, or something like that, it actually tries to print it in a form that would be acceptable syntax in Python for creating that object. And so for example, another aggregate type is the list, which has square brackets. And if I define it like that, then the print statement will print it like that. So the assignment operator is used for assigning a value in Python, and it will also create an object if that object has not already been created.
Find answers to the most frequently asked questions about Python 3 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.