Python @ Codecademy

badge_Python_statisticsInternet Protocols and Support


None keyword
example: i = A
i = None

Building lists
evens_to_50 = [i for i in range(51) if i % 2 == 0]

print(filter(lambda x: x % 3 == 0, my_list))

>>>for i in filter(lambda x: x[0] == “P”, languages):
>>> languages[2]

Just a Little BIT

Welcome to an intro level explanation of bitwise operations in Python!

Bitwise operations might seem a little esoteric and tricky at first, but you’ll get the hang of them pretty quickly.

codecademy_bitwiseclass Fruit(object):
“””A class that makes various tasty fruits.”””
def __init__(self, name, color, flavor, poisonous): = name
self.color = color
self.flavor = flavor
self.poisonous = poisonous

def description(self):
print “I’m a %s %s and I taste %s.” % (self.color,, self.flavor)

def is_edible(self):
if not self.poisonous:
print “Yep! I’m edible.”
print “Don’t eat me! I am super poisonous.”

lemon = Fruit(“lemon”, “yellow”, “sour”, False)


class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return hours * 12.00
def full_time_wage(self, hours):
return super(PartTimeEmployee, self).calculate_wage(hours)


class Car(object):
condition = “new”
def __init__(self, model, color, mpg):
self.model = model
self.color = color
self.mpg   = mpg
def display_car(self):
print “This is a %s %s with %s MPG.” % (self.color, self.model, self.mpg)
def drive_car(self):
self.condition = “used”

my_car = Car(“DeLorean”, “silver”, 88)




class ElectricCar(Car):
def __init__(self, model, color, mpg, battery_type):
self.model = model
self.color = color
self.mpg = mpg
self.battery_type = battery_type

my_car = ElectricCar(“Dodge Stratus”, “white”, 18,”molten salt”)
{Is there need to re-define everything??}

Codecademy_Classes2my_list = [i**2 for i in range(1,11)]
# Generates a list of squares of the numbers 1 – 10

f = open(“output.txt”, “w”)

for item in my_list:
f.write(str(item) + “\n”)



with open(“text.txt”, “w”) as textfile:

with open(“text.txt”, “w”) as my_file:
my_file.write(“I am Sam”)



One thought on “Python @ Codecademy

  1. Pingback: Lambda expressions | franzcalvo

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s