Learn Python the Hard Way

From Hackerspace.gr
Revision as of 22:56, 15 November 2015 by Ebal (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Learn python the hard way.jpg

external link
Starts Organizer
Mon 09 Nov 2015 18:30
Ends Event Owner
Mon 09 Nov 2015 20:30 User:Ebal
  • Κάθε Δευτέρα, 18:30-20:30
  • Συναντήσεις για εκμάθηση προγραμματισμού σε python.

Θα είναι υπό την μορφή study group, δηλαδή όλοι θα μαθαίνουμε παρέα και δεν θα υπάρχει κάποιος "δάσκαλος". Οι συναντήσεις είναι ανοιχτές σε όλες και όλους - αρκεί να φέρεις το laptop σου! Απευθύνονται σε ανθρώπους που θέλουν να ξεκινήσουν με python κι άρα θα είναι αρκετά εισαγωγικές. Η μοναδική δέσμευση είναι να τηρηθεί αυστηρά το ωράριο (δηλαδή εάν κάποιος ή κάποια αργήσει, να μην μας ζητήσει να γυρίσουμε πίσω για να καλύψουμε κάτι που έχουμε ήδη πει).


  • Στις προηγούμενες συναντήσεις έχουμε καλύψει μέχρι και την:

Exercise 35: Branches and Functions

http://learnpythonthehardway.org/book/ex35.html


notes on previous event:

https://www.hackerspace.gr/wiki/index.php?title=Learn_Python_the_Hard_Way_20151026





notes1.py

#!/usr/bin/python2

# for i in range(1,20,2):
# 	if i == 15: 
# 		continue
# 	print "for loop 1 %d" % i
# 	for j in range(2,8,3):
# 		print "for loop 2 %d" % j
# 		if j == 5:
# 			break

		

## name = "ebal"
## 
## 
## if name == "dimi":
## 	print "dimi"
## elif name == "ebal":
## 	print "ebal"
## else:
## 	print "maria"

def ebal1():
	print "ebal1"
	def ebal2():
		return "ebal2"
	return ebal2()


print ebal1()


def mydeco(var1):
	return "variable one"

def hello():
	print "hello"



# IP patterns
ipv4_re = r'(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'
ipv6_re = r'\[[0-9a-f:\.]+\]'  # (simple regex, validated later)

print "ipv4_re %r " % ipv4_re 
print "ipv6_re %r " % ipv6_re

var2 = "test"

# var1 = raw_input("?> ")
# var2 = input(">? ")

# print var1
# print var2 

def _(orig):
	return orig
	
message = _('Enter a valid URL.')

print message


print("")

print ""


def example1():
	mess = ['lobster Thermidor', 'crevettes', 'Mornay']
	for item in mess:
		yield item
		#raise StopIteration

example1()

notes2.py

def foo():
    for i in range(4):
        yield i

def bug():
    return [1,2,3,4]
   
def foo_with_yield():
    yield 1
    yield 2
    yield 3

# iterative calls
for i in foo():
    print i

#x=foo_with_yield()

print foo()
print next(foo())
print next(bug())

print 'test'   
for yield_value in foo_with_yield():
    print yield_value  
   

def foo_with_yield():
    yield 1
    yield 2
    yield 3

x=foo_with_yield()
#print x
print next(x)
   
   

notes3.py

#!/usr/bin/python2

#pernas mia synartisi san parametro

def fun1():
	print "World 1"

# define a function with name shout that accepts one argument
def shout(a):
	# ??? - esoteric function
	def inner():
		# print msg
	    print "Hello ",
	    # call function a (argument 1)
	    a()
	# return through shout the output of inner function (the print statement)
	return inner

# run shout function with func1 as argument. 
# be carefull on the last ()
shout(fun1)()


# alternative - decorators

# wrap function2 with shout2

def shout2(b):
	# still dont know what is this!
	def inner2():
	    print "Hello ",
	    b()
	return inner2

@shout2
def func2():
	print "World 2"


func2()