Python @ Codecademy

badge_Python_statisticsInternet Protocols and Support
https://docs.python.org/3.4/library/internet.html

https://docs.python.org/3.4/library/urllib.request.html

====================================

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):
print(i)
Python
>>> languages[2]
‘Python’

badge_Python_advanced_topics
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):
self.name = 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.name, self.flavor)

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

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

lemon.description()
lemon.is_edible()

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)

codecademy_classes

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)

print(my_car.condition)

my_car.drive_car()

print(my_car.condition)

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”)

f.close()

=============

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

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

Codecademy_FileIO

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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