Nyble a Day

Articles dans la catégorie «py-intro» :

PY-Into 1

Dans «py-intro» par Ed Rantanen

python

Why use python?

it's is open source
it was created by Guido Van Rossum
It has a ton of modules
It was some crazy software built with it such as blender
and for more background its wiki is @ Python

python shell

From a terminal windows type "Python …

PY-Into 2

Dans «py-intro» par Ed Rantanen

comments

pound sign
3 back ticks
example of comments: example: comments

variables

bag_full_of_candy = 5

box = bag_full_of_candy * 5

x = 2
y = 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

Dans «py-intro» par Ed Rantanen

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]
The -1 syntax is quite interesting, try it in the python shell.
What is the result?
Doing a …

PY-Into 4

Dans «py-intro» par Ed Rantanen

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

Dans «py-intro» par Ed Rantanen

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.

simple …

PY-Into 6

Dans «py-intro» par Ed Rantanen

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 function
A print statement

From lesson 1 we saw c = a**2 + b …