Monday, January 9, 2012

Intro to Python Notes

Integrated window--IDLE. Type in, responds directly. There are a lot of things that python just does automatically, through automatic presets--simpler once you know it, but more of a learning curve. Python is case sensitive.

If you want to get decimals, you need to include at least one of the numbers as a non integers. 19.0/3 will return decimals, 19/3 will only return a integer--6. Standard order of operations. 19%3=1  % is the character for 'remainder'. Considered as 'division' in order of operations. ^ is not used for exponent--** is used instead.

Alt+P retypes the last command you exectuted--may 'scroll back' through multiple commands--not just last, but commands previous to that.
#/Sharp/Hashtag used for commenting.
Used for commenting code.  

Seems like variables can be any string. Will accept strings or numbers.

Allows and echo like:
frog*6 gets communismcommunismcommunismcommunismcommunismcommunism
May set mathematical operations as variables:

Saving, must add the extension .py. If you miss it, not critical--will have to open IDLE and then open the file rather than just being able to double-click it.

Create new is out of the main python terminal, which allows you to execute multiple line scripts. In the main editor it runs each line as you type it in.

Variable types = string, number, tuple, list, dictionary...
List needs end-brackets [], separated by commas.

>>> print "My number is", MyNum
My number is 1
#automatically adds the space before a variable?

"append" adds a name to a list.
>>> names.append('catherine')

No comments:

Post a Comment