Articles dans la catégorie «py-intro» :
index
PY-Prelim
- Getting setup:
- A couple of things before we begin to code.
- Python
- https://www.python.org/downloads
- A work area
- https://www.jetbrains.com/pycharm/
Test:
After downloads are accomplished
- Make a project in pycharm.
- Add a python file
- Look at the example
- example: test 1
- Run example code. ("green …
PY-Into 1
PY-Into 2
comments
variables
bag_full_of_candy = 5
box = bag_full_of_candy * 5
x = 2y = 4
data structures
tuple : position =(x,y)
- list :
- routes = []routes.append(position)
Note: Latitude is "0" at equator, "90" north pole / "-90" at south pole
- dictionary :
- fisheries_area = {}fisheries_area["cod"] = (x …
PY-Into 3
strings
- Python has some really interesting tools to work with strings
- strings are groups of letters and/or numbers
blah = "Beam Me Up, Scotty"
blah[0]
blah[:3]
blah[:-2]
blah[::-1]
PY-Into 4
for loops
Lets start with a "for" loop, you can think of this as number of revolutions; if only one number is used such as 10 as a static number it is very limiting.
for elm in range(10):
res = elm * 2
print(res)
A for loop using a single …
PY-Into 5
getopt
getopt is a library for utilizing command line options. By adding arguments we can extend simple static variables.
As we have worked with Pythagorean expression, all the variables have been static in nature now with we can make a utility that that will take any combination of numbers.
PY-Into 6
Functions
A function, What is it?
It is away to create re-usable code; something you might use more than once or away of creating blocks of code that are more easily read.
- As an example:
A Math functionA print statement
From lesson 1 we saw c = a**2 + b …