I have seen class 2 of the MIT course today.
- Nothing much different from what I learned in Udacity 101. Basics Loops, Booleans.
- Types are important (integer, string, float…) and programs sometimes are more or less rigurous in doing type checks. Python is somewhat rigurous and will not allow you for instance to add “abc” + 3.
- Interesting than in python you can for instance do x = 3, wich gives value of 3 to x, and also type integer, and later do x = “abc” which gives value of abc to x and type string. So the types can change. One needs to be careful then, and try to NOT arbitrarily use variables and change their types along the way, or big problems can be caused later one. This the teacher says is “Type Style”
On image you can see a code I wrote on sublimetext, which is going to be my text editor by choice for now and I am loving it. On the top is the function the teacher did in class to distinguish odd or even. Below I propose mine, which I think is more logical, and doesn’t “play” with the fact that on first section the division is one of integers, which, by ignoring the reminder, then makes the formula work (otherwise formula wouldn’t make sense).
Python Input Functions
- input (reads input string as python expression and evaluates it)
- raw_input (returns input represented as a string)
An interesting use of raw_input is that you can for example use it to “freeze” the command window on windows whenever you have a program. For example if you make a program and save the file .py and the program is just printing some text and you run it, it will open and run and close so quickly that you can’t really see anything. However if you add at the end raw_input (“press <enter>”) for example… you will be able to see the result of the running on the program and window will only close after you press enter (or any key for that matter).