 Okay. So Python is an interpreted language. So how many of you are aware of what is interpreted and what's compiled? Basically Python doesn't have a compile cycle, which means you don't have to compile code explicitly and then execute it. You can, it interprets it as you type it in. And these languages as I explained before allow you for rapid testing and prototyping. So if you want to build an architecture, you want to build a bunch of objects, you can just type it out and execute it. And this works and it does scale. So I have programs and applications that scale up to 20,000, 30,000 lines. And it works. There's no problem. And of course, these are applications where I'm talking of my code being 10,000 or 20,000 lines. It's probably using another 50,000 or 100,000 lines elsewhere. And it's importing things from various places. And all of this is done dynamically. So it actually does scale. So, and it allows for rapid testing and prototyping. It's dynamically typed, which means you never explicitly type a particular variable. This is a huge feature. It supports what's called full introspection at runtime, which means if you are given an object, I can find out what the object's documentation is, I can find out what are its methods or what are the attributes it has, all of this dynamically, which means I can use this fact to write dynamic programs. It's pretty useful. The nice thing about Python is unlike certain languages, it does not force object orientation on you. You don't have to say subclass something in order to say print something to screen. You can write nice programs which are completely procedural. You don't have to do object-oriented programming. And that's again very useful because it doesn't force anything on you. So I'm going to follow the Python tutorial. And one big thing people who have not used Python is that Python has no lexical blocking. So if you use C, you have a curly brace, right? Supposing you have an if block, you start it with one parenthesis and then end it with the other parenthesis. And that denotes that this is a particular block that needs to be executed. Python doesn't do it this way. Python uses what's called indentation, which means you indent your code. I'll show you in examples. And this usually drives people away initially from Python. But I think you have to grow over that and you'll realize that good programs are well-indented. So if you're trying to understand somebody else's code, if the code is very well-indented, it's a lot easier to follow the language, follow what is being written. And I've seen this a lot with students' codes. And see, you have things which you have no clue whether it's this part of the loop and then you have to actually go and look at the lines and then figure out, you literally have to interpret the entire code. You can't organize it into nice blocks. Most of us organize things by breaking them up into neat pieces. So indentation kind of forces this to be done on all Python programs, which means the way I indent my code is kind of the same as you indent your code. So if you read my code, it's the same structure, which means when you read somebody else's code, it's a lot easier for you to follow. So it's an advantage in my opinion. And so don't let this drive you away from Python. So how do you start up Python? You basically start it up as Python, or I'm going to introduce an enhanced interpreter called Ipython. To exit, you type control D, you can use this interpreter as a calculator. And it has a bunch of command line options, which I'm not going to show you, but I'll just start up Python. And you have an interpreter that's there. So I can say print hello world or something like that. It does that. I press control D, it quits. Same way with Ipython is an enhanced interpreter. Kind of the same thing. It looks slightly different. I could use it as a calculator. I can say one plus two. Now, the interpreter that I'm going to recommend and we're going to use in the course, the lab sessions is Ipython. And the reasons for that are it's a lot better than the default shell in the sense that it is a Python program. So it's not something different from Python. It's written in Python, but it provides you an interpreter which supports tab completion by default. I'll explain each of these in a bit. It allows for very easy, very convenient object introspection. In fact, sometimes when I go on a shell and I do things that I would do in Ipython and I'm like frustrated that I can't do it on a normal shell. It actually gives you shell access, which means you can use it as a shell. You can actually start up programs from it. You can CD, things like that. It has a command system that allows you to extend its own behavior. So you can define aliases. You can define commands of your own. It supports history across sessions, which means I typed something two days back. I can search for that and have it show up right now. It can be embedded in your own Python code. It supports macros, which are extremely convenient when you're doing interactive things and lots of other conveniences. And I'll cover various aspects of Ipython as we move along. But for now, I'm just going to introduce the basic core features that you're going to need for today. You start it as Ipython as I just showed you. It has certain options. You will see me typing Ipython minus W thread or something like that. So these are basically threading modes that let you support WX Python or GTK or QT. So if I want to create a QT window, QT has its own loop of execution or WX Python. If you create a window, a window has an event loop based processing framework, which means somebody clicks some button, do this. And so each of these things has a loop where it's actually looking for user events. So if you did this from a standard interpreter, it will just stop. It won't do anything. So Ipython has a special mode that lets you sort of fire these off while you have interactive power. And this is extremely useful when you're doing plotting. So I want to plot something quick. I still want my interpreter. That's the key. So these modes basically let you do these things. And it's built in with Ipython. The big thing is that it supports what's called tab completion. So for example, if I say A is some string, we'll do strings in a bit. A dot tab shows me all the methods that a string has. So this is the first thing. So if I can say A dot, say C tab, it automatically completes the count. I don't have to type. So if you have, if you write a good library, you actually use descriptive names. You don't say A dot C, meaningless. You say A dot count the number of words in this file. Okay, that's a long method. But if you did have something like that, and you had Ipython, you can just tab complete. So it's extremely handy. The other thing is I don't know what count does. I don't know what count is. So I can say A dot count. So it's a built in method, which means it's a function. Now I can say question mark. It actually gives me help. It says return the number of non-overlapping occurrences of substring sub in string, blah, blah, blah, which is the documentation for this particular method. And all it took was a question mark and an enter. So it's extremely convenient. So object question mark shows your dark string help object double question mark will even show you source code if it can. So which means I have some object on function. And I want to know what that function is. You just say double question mark. It lets you do debugging. So if you run into an error, you can turn on a flag called PDB, which actually will pop you into that particular location where you're trying to debug. You can access history. So which means if I do app arrow, it's actually going over all the stuff I typed a long time ago. If you type control R, you can actually search. So I can say control R C equals. And it actually finds what I wanted. So this is very, very convenient. The other thing is once you've gone up the history, you want to get back. And that's the last command escape. This arrow will give you back there. The last thing is run, which means if you have a Python file and you want to execute it, you can say run file name. And it'll actually run that program in a separate thing. So which means it's very convenient to do things and run actually has a bunch of options which we'll cover later. So with this, you can actually get started with programming with Python. Basically, Python is dynamically typed, which means I don't have to specify a type at assignment time. So I can say is one or is 1.1 or is foo, or is an instance of a class. It doesn't matter. Comments are specified by the hash symbol that you see here. You can have inline comments, and you can have comments on a line by themselves. Obviously, if you put something in a string, comment in a string, it's not a comment. So it's smart enough to figure that out. The other thing, as I mentioned earlier, is there is no lexical scoping, which means you use indentation to determine scope. So if you had a for loop, we will cover for loops in a little while, but just showing you the idea of how indentation works. This is very important. So when you write your codes, you have to really make sure that it's indented right. It's very important. And once you start doing it, it becomes automatic. So you don't have to worry about it. So in this case, these two lines print inside loop print something else are inside a loop. So they will be executed 10 times. The line just outside is only executed after the loop is executed. So it's executed. So this is the general idea. So if ever you see a block of code, it's pretty straightforward, you know exactly that the stuff that's indented to the right over here is what's inside the loop. The other thing is, in Python, an assignment is to an object is by reference. So copies are only made if you explicitly ask for them using something called a copy module. So if you say b equals a, b is actually just a reference to a, or actually b is a reference to the object that a is referring to. So if I say a equals one, there is a one object somewhere on in memory. And a is a name that is bound to that one. So think of it as a house and addresses. So you have, don't think of it as C plus plus or C addresses. An address or for example, my name is bound to me in some sense. It is not me. So if somebody can call me sir, or hey, or something like that, but they refer to the same person. I don't change. You don't have a copy of me. The same notion holds in Python. So essentially names are bound to objects. So there are objects somewhere and you have names point to that. So when you say a equals something, and then you say b equals a, b is again pointing to that same object, not to a.