Monday, August 25, 2014
Slicing a list
See example below to call part of a list.
Notice that if you want to include 8 the end slice has to be 9.
Sequences and lists
The basic structure for creating a list is as follows:
Name = [‘type1’,’type2’,’type3’,’type4’]
See example below.
The list starts numbering with 0. Notice how when cars[0] is called after the list is created the name that shows up is Mercedes.
Strings
The variable needs to be treated as a string in order for the concatenation to work.
Saving Programs
In IDLE file new window
Then file save with extension with .py
Then run (must be saved)
Modules and Functions
Function is a built in program.
1.
Needs a parameters
a.
Pow (5,4) is the same as 5**4
i.
5 and 4 are parameters
abs ( -5) is a absolute value function
Module
1.
Have to be imported
2.
Import math <press enter>
a.
math.floor (18.7)
b.
math.sqrt
(81)
c.
square = math.sqrt; use variable name assigned
to function/module
Modules as variables
Tuesday, August 19, 2014
Basic Math in Python
After installing Python 2 Open IDLE (Python GUI). IDLE stands for
Integrated DeveLopment Environment.
Basic math functions are not complicated in IDLE. Just type 4+4 at the prompt and see
what happens.
Interesting difference between 18/7 and 18.0/7. This illustrates the difference between an
integer and a Float.
How about 18%7? % gives you the remainder for the division function.
How would you write 8 to the third power? Try 8*8*8, or 8**3.
Integrated DeveLopment Environment.
Basic math functions are not complicated in IDLE. Just type 4+4 at the prompt and see
what happens.
Interesting difference between 18/7 and 18.0/7. This illustrates the difference between an
integer and a Float.
How about 18%7? % gives you the remainder for the division function.
How would you write 8 to the third power? Try 8*8*8, or 8**3.
Getting Started (Installing Python)
Install Python version 2 or 3 from python.org. I have installed python 2,
since resources I am using to learn python are using Python 2.
Please see link below for differences between Python 2 and 3.
https://wiki.python.org/moin/Python2orPython3
since resources I am using to learn python are using Python 2.
Please see link below for differences between Python 2 and 3.
https://wiki.python.org/moin/Python2orPython3
Subscribe to:
Posts (Atom)