[Thema: Software]
By the way, the language is named after the BBC show "Monty Python's Flying Circus" and has nothing to do with nasty reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!
Quelle: Python tutorial
Und hier wirds pervers:
When a final formal parameter of the form **name is present, it receives a dictionary containing all keyword arguments except for those corresponding to a formal parameter. This may be combined with a formal parameter of the form *name (described in the next subsection) which receives a tuple containing the positional arguments beyond the formal parameter list. (*name must occur before **name.)
Ein Dictionary in Python entspricht einem Hash in Perl. So wird es angelegt:
EDIT: Auch interessant: Deutsche Wikipedia über Python
Quelle: Python tutorial
def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): print "-- This parrot wouldn't", action, print "if you put", voltage, "volts through it." print "-- Lovely plumage, the", type print "-- It's", state, "!"Hmm, ein quote?
Und hier wirds pervers:
When a final formal parameter of the form **name is present, it receives a dictionary containing all keyword arguments except for those corresponding to a formal parameter. This may be combined with a formal parameter of the form *name (described in the next subsection) which receives a tuple containing the positional arguments beyond the formal parameter list. (*name must occur before **name.)
Ein Dictionary in Python entspricht einem Hash in Perl. So wird es angelegt:
knights = {'gallahad': 'the pure', 'robin': 'the brave'}Eine Sequenz in Python entspricht einem Array in Perl. So wird sie angelegt:
questions = ['name', 'quest', 'favorite color']Mit der zip() Function kann man über mehrere Sequenzen auf einmal laufen - sehr schick:
>>> questions = ['name', 'quest', 'favorite color'] >>> answers = ['lancelot', 'the holy grail', 'blue'] >>> for q, a in zip(questions, answers): ... print 'What is your %s? It is %s.' % (q, a) ... What is your name? It is lancelot. What is your quest? It is the holy grail. What is your favorite color? It is blue.Dateien mit Endung .py sind Python-Module. Mit der Anweisung
import fibokann z.B. das Modul fibo.py geladen werden. In diesem File kann z.B. eine Funktion fib definiert werden. Nach dem Befehl import fibo kann diese dann mit
fibo.fib(3)aufgerufen werden, oder mit
irgendwas = fibo.fib irgendwas(3)Module werden im aktuellen Pfad gesucht und in den Pfaden, die mit der Umgebungsvariable PYTHONPATH angegeben werden, und schließlich in einem system-abhängigen Pfad. Die Syntax der Variable PYTHONPATH entspricht der von PATH.
EDIT: Auch interessant: Deutsche Wikipedia über Python
Freitag, 24. Februar 2006, 11:49, von moolder