Python Notes

Basic

 len = length
 phrase.index
 phrase.replace
 modulus operator % - leftover after divide operation
 input("prompt")

Lists

[] square brackets = list
 [1:3] range elemets i list
 .extend() - adds lists together
 .append() -adds an item to the end
 .insert() - (1, item) adds item to position 1
 .remove() - removes particular item
 .clear - clears the whole list
 .pop - removes last element of list
 .index - gives the index of item
 .count - how many times a particular value is in the list
 .sort - ascending order
 .reverse
 .copy

Tuple

container for different values
 can't change
 xxx = ()

Functions

def xxx(parameter):
 lowercase names
    RETURN STATEMENT
   return 
if xxx:
 if xxx or yyy: one must be true
 if xxx and yyy: both must be true
elif - else if
elif xxx and not (yyy): - will change yyy to oposite

Operators

!= not equal
== equal
= greater or equal to 
2**3 = 2^3

Types

float(input("Enter number)) - converts to float
str()-konvertuje na string
abs() - absolutna value
pow(cislo, exponent)
round - rounding value

Math

from math import*
floor - chops off decimal point
ceil - round value up
sqrt - shows square root

Dictionaries

xxx = {yyy:zzz,} yyy asociates to zzz
open("employees.txt","r")
 r read, w write, a append, r+ read and write

Loops

while
 i+=1 - i + 1
 and not() - one OR the other option

For loop

for index in range(3):
 index = 0, 1, 2,  - for every itteration

Nested for loop

 for row in number_grid:
      for col in row:
 print (col)
COMMENTS - use hashtags

Resources:

https://realpython.com/python-testing/

https://www.w3schools.com/python/python_functions.asp

Share This:

Program along with Joey Ramone!

I came along this interview by chance, and I thought you might like it.

Joey Ramone in the 1984 Issue of K-Power computer magazine

Here is the part of the interview I really like and relate to, Joey could see to the future, no question…

“I think it’s interesting and exciting (the computers) – I just hate to see it get out of hand. I like the basic things. I can appreciate computers, but I’d like to see kids take chances. Kids are so conservative today. I think the computer age is a big part of it. Computers can become too much like a crutch. I think kids need to experience more stuff that’s real.”

That implies not only to kids now days. I think.

Read more here, page 38:

http://www.scribd.com/doc/53854808/K-Power-Issue-02-1984-Mar

Share This: