Difference between revisions of "Learn Python the Hard Way 20151207"
From Hackerspace.gr
(Created page with "{{Event |logo=Learn python the hard way.jpg |what=Learn Python the Hard Way |tagline=* Κάθε Δευτέρα, 18:30-20:30 * Συναντήσεις για εκμάθηση ...") |
|||
Line 30: | Line 30: | ||
|location=38.01694322164, 23.731269990513 | |location=38.01694322164, 23.731269990513 | ||
}} | }} | ||
+ | |||
+ | |||
+ | |||
+ | notes | ||
+ | |||
+ | |||
+ | '''mymodule.py''' | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | def myname(name): | ||
+ | print name | ||
+ | |||
+ | def mylastname(sname): | ||
+ | print sname | ||
+ | |||
+ | def myage(age): | ||
+ | print age | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | |||
+ | '''myclass.py''' | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | class MyStuff(object): | ||
+ | |||
+ | def __init__(self): | ||
+ | self.tangerine = "And now a thousand years between" | ||
+ | |||
+ | def apple(self): | ||
+ | print "I am classy apples!" | ||
+ | |||
+ | name="ebal" | ||
+ | |||
+ | # create a new class with name Song | ||
+ | class Song(object): | ||
+ | |||
+ | def __init__(self, lyrics): | ||
+ | self.lyrics = lyrics | ||
+ | |||
+ | def sing_me_a_song(self): | ||
+ | for item in self.lyrics: | ||
+ | print item | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | '''40a.py''' | ||
+ | |||
+ | <pre> | ||
+ | |||
+ | # import a specific function | ||
+ | from mymodule import myage | ||
+ | myage(20) | ||
+ | |||
+ | # or the entire module | ||
+ | print "#"*20 | ||
+ | |||
+ | import mymodule | ||
+ | mymodule.myage(20) | ||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | # import entire module | ||
+ | |||
+ | import myclass | ||
+ | |||
+ | a = myclass.MyStuff() | ||
+ | |||
+ | a.apple() | ||
+ | |||
+ | # or | ||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | # you can import a class !! | ||
+ | from myclass import MyStuff | ||
+ | |||
+ | a = MyStuff() | ||
+ | |||
+ | a.apple() | ||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | # You can also import a variable !!!! | ||
+ | |||
+ | from myclass import name | ||
+ | |||
+ | print name | ||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | # ex40 | ||
+ | |||
+ | # create a new variable (object/instance) of class MyStuff | ||
+ | thing = MyStuff() | ||
+ | thing.apple() | ||
+ | #print thing.tangerine | ||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | print thing.__init__() | ||
+ | |||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | from myclass import Song | ||
+ | |||
+ | happy_bday = Song( | ||
+ | [ | ||
+ | "Happy Birtday to you", | ||
+ | "I dont want to get sued", | ||
+ | "So I'll stop right there" | ||
+ | ] | ||
+ | ) | ||
+ | |||
+ | bulls_on_parage = Song ( | ||
+ | [ | ||
+ | "The rally around tha family", | ||
+ | "With pockets full of shell" | ||
+ | ] | ||
+ | ) | ||
+ | |||
+ | happy_bday.sing_me_a_song() | ||
+ | |||
+ | print "" | ||
+ | |||
+ | bulls_on_parage.sing_me_a_song() | ||
+ | |||
+ | print "#"*20 | ||
+ | |||
+ | a = [ | ||
+ | "Happy Birtday to you", | ||
+ | "I dont want to get sued", | ||
+ | "So I'll stop right there", | ||
+ | "The rally around tha family", | ||
+ | "With pockets full of shell", | ||
+ | ] | ||
+ | |||
+ | b = Song(a) | ||
+ | b.sing_me_a_song() | ||
+ | |||
+ | </pre> |
Latest revision as of 20:58, 7 December 2015
external link |
Starts | Organizer |
---|---|---|
Mon 07 Dec 2015 18:30 | ||
Ends | Event Owner | |
Mon 07 Dec 2015 20:30 | User:Ebal |
- Κάθε Δευτέρα, 18:30-20:30
- Συναντήσεις για εκμάθηση προγραμματισμού σε python.
Θα είναι υπό την μορφή study group, δηλαδή όλοι θα μαθαίνουμε παρέα και δεν θα υπάρχει κάποιος "δάσκαλος". Οι συναντήσεις είναι ανοιχτές σε όλες και όλους - αρκεί να φέρεις το laptop σου! Απευθύνονται σε ανθρώπους που θέλουν να ξεκινήσουν με python κι άρα θα είναι αρκετά εισαγωγικές. Η μοναδική δέσμευση είναι να τηρηθεί αυστηρά το ωράριο (δηλαδή εάν κάποιος ή κάποια αργήσει, να μην μας ζητήσει να γυρίσουμε πίσω για να καλύψουμε κάτι που έχουμε ήδη πει).
- Θα ακολουθήσουμε την παρακάτω ύλη: http://learnpythonthehardway.org/book/
- Στις προηγούμενες συναντήσεις έχουμε καλύψει μέχρι και την:
Exercise 39: Dictionaries, Oh Lovely Dictionaries
http://learnpythonthehardway.org/book/ex39.html
notes on previous event:
https://www.hackerspace.gr/wiki/Learn_Python_the_Hard_Way_20151130
notes
mymodule.py
def myname(name): print name def mylastname(sname): print sname def myage(age): print age
myclass.py
class MyStuff(object): def __init__(self): self.tangerine = "And now a thousand years between" def apple(self): print "I am classy apples!" name="ebal" # create a new class with name Song class Song(object): def __init__(self, lyrics): self.lyrics = lyrics def sing_me_a_song(self): for item in self.lyrics: print item
40a.py
# import a specific function from mymodule import myage myage(20) # or the entire module print "#"*20 import mymodule mymodule.myage(20) print "#"*20 # import entire module import myclass a = myclass.MyStuff() a.apple() # or print "#"*20 # you can import a class !! from myclass import MyStuff a = MyStuff() a.apple() print "#"*20 # You can also import a variable !!!! from myclass import name print name print "#"*20 # ex40 # create a new variable (object/instance) of class MyStuff thing = MyStuff() thing.apple() #print thing.tangerine print "#"*20 print thing.__init__() print "#"*20 from myclass import Song happy_bday = Song( [ "Happy Birtday to you", "I dont want to get sued", "So I'll stop right there" ] ) bulls_on_parage = Song ( [ "The rally around tha family", "With pockets full of shell" ] ) happy_bday.sing_me_a_song() print "" bulls_on_parage.sing_me_a_song() print "#"*20 a = [ "Happy Birtday to you", "I dont want to get sued", "So I'll stop right there", "The rally around tha family", "With pockets full of shell", ] b = Song(a) b.sing_me_a_song()