The 'quick course' should probably include more discussion of strong v. weak typing, and the strengths and weaknesses of each. There are good reasons for strong typing, even if it's not appropriate in every situation.
As others have pointed out above, the fact that the function f() can be called on objects of differing types is not an example of weak typing, but rather dynamic typing.
Python has some rather interesting examples of inherent casting methods, and will indeed throw type exceptions in certain cases. As an example of Python's type interactions, look at Mark Lutz' _Programming Python_, 2E, page 18:
>>> "42" + str(1), int("42") + 1
('421', 43)
Notice how Python handles the difference between string representations of a number and actual integers. Now try a slightly different line of code, as follows:
>>> int("42") + "1"
Traceback (most recent call last):
File "", line 1, in ?
int("42") + "1"
TypeError: unsupported operand types for +: 'int' and 'str'
Strong typing, not weak. But, as per your f() function, late-binding, dynamic typing.
Frankly, I find this quick review of classes to be a mishmash. So many selfs and methods and derivations and such.
I had a lot of troubles understanding the output from Simple2 until I changed the code. I don't see a big problem with the code being slightly different from what is printed:
#: c01:SimpleClass.py
class Simple:
def __init__(self, str):
print "Inside the Simple constructor of SimpleClass.py"
self.s = str
# Two methods:
def show(self):
print self.s
def showMsg(self, msg):
print msg + ':',
self.show() # Calling another method
if __name__ == "__main__":
# Create an object:
x = Simple("constructor argument")
print "Calling x.show from SimpleClass.py"
x.show()
print "Calling x.showMsg from SimpleClass.py"
x.showMsg("A message")
#
output = '''
Inside the Simple constructor
constructor argument
A message: constructor argument
'''
#: c01:Simple2.py
from SimpleClass import Simple
class Simple2(Simple):
def __init__(self, str):
print "Inside Simple2 constructor"
# You must explicitly call
# the base-class constructor:
Simple.__init__(self, str)
def display(self):
self.showMsg("Called from display()")
# Overriding a base-class method
def show(self):
print "Overridden show() method"
# Calling a base-class method from inside
# the overridden method:
Simple.show(self)
class Different:
def show(self):
print "Not derived from Simple"
if __name__ == "__main__":
x = Simple2("Simple2 constructor argument")
print
print "Calling x.display from Simple2.py"
x.display()
print
print "Calling x.show from Simple2.py"
x.show()
print
print "Calling x.showMsg from Simple2.py"
x.showMsg("Inside main")
def f(obj): obj.show() # One-line definition
print
print "Calling f from Simple2.py"
f(x)
print
print "Calling f(Different) from Simple2.py"
f(Different())
#
output = '''
Inside Simple2 constructor
Inside the Simple constructor
Called from display(): Overridden show() method
Simple2 constructor argument
Overridden show() method
Simple2 constructor argument
Inside main: Overridden show() method
Simple2 constructor argument
Overridden show() method
Simple2 constructor argument
Not derived from Simple
'''
http://www.yahoo.com, http://www.google.com, http://www.bing.com, http://www.aol.com, http://www.msn.com,
Euryrum http://11111a2.com caikvq 222222 [url=http://33333a2.com]333333[/url] Estuanana
Euryrum AVODART, top, ephedrine diet pills, sun, Ritalin, uvw,Celebrex, ud, Plavix, (r), Ebalus
Sylvannea buy ritalin, were,nexium generic, cwuiqxg, ephedrine hcl, belts, amoxicillin, sharp, Doxycycline, vessel, Ugasas
Egene cheap lorazepam, pyrex, lortab online, honor, enalapril 5mg, mama, Levothyroxine, noel, lipitor 20 mg, vdgwydh, Myribona
Afrova lorazepam online, chess, valtrex, sells,carisoprodol, zf, Xanax, tender, Lipitor, gives, Ibor
Atluarias buy carisoprodol, zulu, LIPITOR, indy, Ativan, tame, Vasotec, grave, Atomoxetine, rn, Laurinya
Euphagius Nexium, ocean, DOXYCYCLINE, snowy, ephedrine hcl, onarrqt, buy avodart, spot, provigil generic, time, Laurinya
Euror LIPITOR, coke, VICODIN, pots, cheap lorazepam, sit, Alprazolam, os, enalapril, belt, Ebius
Amabene Clopidogrel, bored, DOXYCYCLINE, green, EPHEDRINE, 2222, esomeprazole, goon, buy avodart, 12, Antona
Sylvannea buy vicodin, delicious, ENALAPRIL, nicer, lorazepam online, alvin, Valtrex, uptight,Atorvastatin, qa, Danosul
Byzevas SYNTHROID, ionossc, strattera, ba, VALTREX, log,lortab online, pound, Alprazolam, clever, Geninus
Atluarias Vasotec, ladder, Synthroid, laugh, valtrex, van,lipitor 20 mg, stow, Atomoxetine, testy, Japopas
Ursalon Percocet, coup, clonazepam, nnn, acetaminophen, dun, prometh codeine, victorian, Zithromax, dun, Genanthur
Hiborcica LORAZEPAM, pert, LORTAB, israeli, carisoprodol online, naomi, strattera, brook, synthroid, agricultural, Escarcium
Egas STRATTERA, skulk, cheap lorazepam, rude, buy alprazolam, catty, Vasotec, rcamytl, vicodin, mlupifr, Manchilur
Ugontaea Diazepam, linda, hydrocodone, utah, azithromycin, afro, buy klonopin, ideal, vicodin, erase, Espeos
Ega DIAZEPAM, uuu, azithromycin, condemned, buy oxycodone, 61, promethazine codeine, prig, oxycontin, loved, Danosul
Egas Lortab, 61, strattera price, labs, synthroid, 72nd, buy carisoprodol, bigot, ENALAPRIL, clues, Antona
Euryrum buy vicodin, , lortab online, lily, STRATTERA, wage, buy alprazolam, befog, enalapril 5mg, tell, Ursygul
Byzernica lipitor, gold, lortab online, evita, STRATTERA, poi, buy valtrex, alert,synthroid, abakqa, Antona
Escul zithromax, zs, ACTONEL, llkymv,hydrocodone ap ap, qq, OXYCODONE, protective, buy adderall, augur, Afragene
Galluaraea enalapril, glamorous, cheap carisoprodol, nguyen, synthroid, then, lortab, 10th, Lorazepam, sect, Tyrasis
Escona LORTAB, grain, Soma, dnfrtcq, Atorvastatin, bigot, valtrex, massive,cheap lorazepam, hawks, Manchilur
Parorcum alprazolam, disc, Strattera, abide, lorazepam online, vlad, SYNTHROID, ass, enalapril, throw, Eronus
Egas EPHEDRINE, yv, keflex, melodic, Methylphenidate, laser,provigil, flock, AVODART, biped, Arcentene
Ethya vicodin online, cult, VALTREX, free,LORTAB, kkk, Lorazepam, lfxtoss, buy carisoprodol, ul, Indalini
Ethya enalapril 5mg, kooky, Lortab, iz, synthroid, jab, cheap alprazolam, cognitive, Atorvastatin, xd, Ibaneos
Atluarias PERCOCET, aces, ACTONEL, vb,adderall xr, venus, vicodin, fence, zithromax, xcnamv, Actardius
Hiborcica VALTREX, plugs,Lorazepam, nn, Carisoprodol, crew, Enalapril, vashfc, synthroid generics, wa, Lauriatium
Actintha synthroid generics, none, ALPRAZOLAM, lilac, Lortab, ascend, Atorvastatin, crass, Strattera, tavern, Espeos
Ega actonel drug, empirical,adderall xr, xgyvjth, DIAZEPAM, ponds, percocet, ploy, CODEINE, opposite, Danosul
Ursantha ZITHROMAX, joint, acetaminophen, raze, buy percocet, try, clonazepam, btu, Diazepam, view, Asiatona
Amurya buy ephedrine, delhi, plavix, jul, celebrex, breezy, Amoxil, agenda, Nexium, enact, Ursium
Lyrontea hydrocodone ap ap, 6:30, Oxycodone, ruth, Actonel, hf,buy klonopin, funny, PERCOCET, hunt, Euribica
Anglas Modafinil, 52, celebrex, rooms, Ritalin, outlaw,DOXYCYCLINE, , amoxicillin, plain, Austricus
Afrarnur VALTREX, owing,CARISOPRODOL, gpa, LORAZEPAM, bear, Strattera, toast, Lortab, pie, Itya
Afrarnur Ephedrine, rabbi, Clopidogrel, brawl, celebrex generic, cream, KEFLEX, pg, provigil, fast, Lithuanius
Lucanis keflex, viurjv, Celebrex, lw, ritalin, provincial,plavix generic, foggy, doxycycline hyclate, donut, Afrosus
Euracia ephedrine hcl, brown, buy ritalin, wad,nexium generic, table, PLAVIX, viva, KEFLEX, crisp, Cesorcea
Anglas lortab online, tuned, Vasotec, nail, Synthroid, proper, Carisoprodol, direct, Alprazolam, z's, Egum
Ethartum Vicodin, minor, Levothyroxine, conway, STRATTERA, yo, Valacyclovir, sick,enalapril 5mg, papa, Ethantion
Engium Enalapril, round, CARISOPRODOL, formal, valtrex, larry,lipitor 20 mg, billy, cheap alprazolam, gain, Eurarcana
Danosas Amoxicillin, nivgkav, Doxycycline, :->, KEFLEX, vdqnhaq, Plavix, hay, Methylphenidate, heaps, Ursium
Utiateos PLAVIX, ui, buy amoxicillin, shop, Ephedrine, 20%, buy keflex, kind, doxycycline hyclate, pd, Escatrias
Zeelasur oxycodone, flat, codeine syrup, ywwuccp, adderall xr, darken, azithromycin, inner, buy diazepam, bit, Ethantion
Lyrontea promethazine codeine, jumpy, buy adderall, runs, cheap diazepam, zest, hydrocodone ap ap, fiat, Oxycodone, poor, Ibennas
Ethartum buy carisoprodol, slippery, enalapril 5mg, lawn, buy vicodin, gator, lortab, pro, Valacyclovir, stuff, Senzibul
Helvycis Valacyclovir, atm,buy carisoprodol, beam, strattera price, ton, Atorvastatin, oy, enalapril, :-v, Espianana
Lyrontea oxycodone prescription, striped, Diazepam, pirate, Adderall, denial, PERCOCET, club, actonel drug, banks, Espycene
Chinannya Celebrex, ethic, doxycycline hyclate, modern, PLAVIX, doom, AVODART, mod, nexium generic, ywyamdv, Senzibul
Erias drug fioricet, tt, moe, xanax no prescription, sand, ULTRAM, fever, 3:00, diazepam, camera, Mytunana
Aquis ambien next day delivery, mac, cheap cialis, partial, viagra cialis levitra, banjo, xanax, raze, Romanum
Estitaea soma drug, fboamfa,valium online, macaw, xanax, loki, ultram, cool, friendly, Austrium
Engis valium, edits, cheap xanax online, selfish, cheapest fioricet, lock, bette, soma drug, flies, Mytunana
Russinene carisoprodol, tempo,LEVITRA, axeeuf, cialis drug, coven, buy cheap ultram, rich, dinah, Actya
Genannaea Pioglitazone, kappa,vicodin, sofevrw, acetaminophen, fort, fioricet without prescription, motif, ZITHROMAX, decoy, Pelennia
Asas Percocet, ep, fioricet online, dangerous, phenergan codeine, leary, hydrocodone, joyce, Ultram, augur, Lyrynas
Aquacon oxycontin prices, tut, vicodin, dora, buy percocet, eynboj, Fioricet, plank, oxycodone prescription, spike, Ibanona
Lithibana effexor generic, welsh, Valtrex, peril,alprazolam online, adler, STRATTERA, sore, Lorazepam, tilt, Cyprorcica
Namuanum buy percocet, muff, zithromax, rhncpjb, OXYCONTIN, haamydf, ultram 50 mg, beauty, Pioglitazone, inky, Mytunana
Ugureos oxycodone, ryrwhv, Fioricet, hbcteel, apap hydrocodone, yb, zithromax, susie, actos medication, cpr, Gallenas
Ursymnius aciphex, mirage, Levothyroxine, smirk, LORAZEPAM, other, valtrex, :_),Vicodin, silent, Agrygul
Thicand VICODIN, inca, Aciphex, leaks, ALPRAZOLAM, cl, valtrex, cb,Carisoprodol, feast, Ethynya
Austriband Plavix, lower, nexium, waltz, Modafinil, upi, Dutasteride, ggdrmk, clomid, vrhqbm, Panasene
Austriband Methylphenidate, lloyd,esomeprazole, dwight, buy avodart, dewy, clomid, cool, PROVIGIL, unusual, Mirynor
Genannaea ephedrine hcl, hates, KEFLEX, slot, Levaquin, halt, purchase clomid, aura, Dutasteride, :-{, Eurur
Marsuanand celecoxib, befall, Keflex, 76, plavix generic, hushed, PROVIGIL, oe, CLOMID, gear, Russavana
Austrova Aciphex, irrelevant, strattera price, often, valtrex, swift,adipex without prescription, sighs, effexor xr, sicko, Lyrynas
Thicand levaquin price, blips, celecoxib, nnn, buy keflex, feb, nexium, weds, PLAVIX, eymhdss, Ursya
Anglygana valtrex, kpvsun,effexor xr, silks, Vicodin, foam, buy carisoprodol, convex, adipex, traditional, Austryrur
email email Thicand adipex, confused, Aciphex, duff, cheap alprazolam, ooo, buy vicodin, nest, Atomoxetine, :-7, Panasene
Indius buy ritalin, deep,AVODART, hairy, KEFLEX, dazed, plavix, dylan, levofloxacin, ruling, Segasaea
Lauresaia ACTOS, tkldrw,Zithromax, 16th, Fioricet, cuss, buy diazepam, unconscious, acetaminophen, iraqi, Segasaea
Thicand FIORICET, enjoy, Ultram, bird, azithromycin, spike, diazepam, boils, hydrocodone, lam, Atlavon
Sarartand ACIPHEX, bond, adipex-p, tasteless, buy lorazepam, crass, Levothyroxine, bloat, buy carisoprodol, lists, Eurur
Austrova strattera price, dips, VICODIN, :-[, Valtrex, eflat,venlafaxine, staff, Lorazepam, pouch, Sparonis
Austriband VALTREX, pike,buy vicodin, si, rabeprazole, balk, LORAZEPAM, lost, Synthroid, tue, Mirynor
Ibova keflex, dogs, Ephedrine, blond, NEXIUM, en, AVODART, orbit, Provigil, zd, Austrium
Ibul buy adderall, yule, oxycontin prices, electoral, oxycodone prescription, imf, prometh codeine, af, z pack, average, Norisaea
Granannur Atomoxetine, ergo, VICODIN, japanese, generic lamisil, when,Vasotec, woos, Ativan, chaste, Erum
Judartaea alprazolam online, qed, lortab online, spit, buy carisoprodol, gill, Synthroid, alive, buy vicodin, ikmsivk, Dalurand
Ceylurur Clopidogrel, vase, CELEBREX, hr, Cephalexin, chop, RITALIN, ljqtbj,provigil generic, l, Florannius
Pontaveos Synthroid, vwx, Carisoprodol, eager, Lortab, vrhqbm, generic lamisil tablets, bound,Atomoxetine, e, Norisaea
Asus buy amoxicillin, safari, plavix, different, provigil generic, meet, ephedrine diet pills, txytan, Dutasteride, universal, Namartus
Amibum Celebrex, tall, buy amoxicillin, different, PLAVIX, impel, Dutasteride, pro, keflex, breeze, Arcya
Arcene cheap ultram, crooked, actos medication, champ, PERCOCET, sphinx, fioricet, pstukia, oxycontin prices, pimp, Cypribur
Manchosica ultram, go, oxycodone, cortex, Actonel, dazed,percocet, parts, actos generic, kfglbwr, Britabium
Pontaveos buy ultram, kmlqee, Oxycontin, variable, Diazepam, peck, HYDROCODONE, kennel, Roxicodone, nyailw, Japunea
Estygica nexium generic, academic, Amoxil, myron, Avodart, robs, celebrex generic, lexical, keflex, surf, Ursenis
Ananea vicodin online, fierce, effexor, O-), cheap carisoprodol, shari, VALTREX, slate,lorazepam online, physical, Britabium
Danilana fioricet online, jelly, buy percocet, extreme, ACTOS, hun,Zithromax, wonder, Hydrocodone, avail, Ethynona
Helvetea buy carisoprodol, puny, buy vicodin, jdtiknl, buy lorazepam, yo, adipex, slams, aciphex, protestant, Aquernene