Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7cce197

Browse files
committed
Updates CodeCamp Los Angeles Nov 2013
1 parent 91b836d commit 7cce197

14 files changed

+69
-51
lines changed

intro/a_code_sample.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@
33
'''
44

55
def add(a, b):
6+
""" add two numeric values """
67
return a + b
78

8-
x = 200
9-
y = 150
10-
z = add(x, y)
11-
12-
if z > 100 and z < 1000:
13-
print "in the hundreds:" ,z
14-
elif z > 0:
15-
print "positive number:" , z
16-
else:
17-
print "negative number"
9+
def get_info(val):
10+
""" print out s"""
11+
if val > 1000:
12+
print "in the thousands:" , val
13+
elif val > 100 and val < 1000:
14+
print "in the hundreds:" , val
15+
elif val > 0:
16+
print "positive number:" , val
17+
else:
18+
print "negative number"
19+
20+
# only execute if this is the main file
21+
if __name__ == "__main__":
22+
x = 200
23+
y = 150
24+
z = add(x, y)
25+
get_info(z)

intro/b_syntax.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"""
1313

1414
# docstring to comment functions / classes etc. Will be used by intellisense / debugger etc.
15-
def function():
16-
""" this function does a lot """
17-
pass # this means don't do anything
15+
def my_function():
16+
""" this function does a lot 12334"""
17+
pass # this means don't do anything
1818

1919
# ----------------------
2020
# Indentation
@@ -33,4 +33,4 @@ def function():
3333
# you can write code after the :
3434
if True: print "one liner also works"
3535

36-
36+

intro/d_basic_datatypes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# ----------------------
77
# first assignment creates name which references value in memory, types are inferred
88
aint = 5
9-
cstr = dstr = "test" # both cstr and dstr will contain the value: test
10-
aint ="test"
9+
cstr = dstr = "test" # both cstr and dstr will contain the value: test
10+
aint = "test"
1111

1212
# ---------------------------
1313
# Numbers
@@ -41,6 +41,6 @@
4141
# string formating
4242
print "part1 '%s' part2 '%s'" % ('a', 'b')
4343

44-
print "part1 '%s' part2 '%s'" % 'b'
44+
print "part1 '%s' " % 'b'
4545

4646

intro/k_references.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
print "\n--- numbers ---"
1010
aint = 5
1111
bint = aint
12+
print "%s,%s | id %s,%s" % (aint, bint, id(aint), id(bint)) # result 6 - 5
1213
aint = 6
13-
print "%s,%s | id %s,%s" % (aint, bint, id(aint), id(bint)) # result 6 - 5
14+
print "%s,%s | id %s,%s" % (aint, bint, id(aint), id(bint)) # result 6 - 5
1415

1516

1617

1718
print "\n--- tuples ---"
1819
atu = (1, 2, 3)
1920
btu = atu
21+
print "%s,%s | id %s,%s" % (atu, btu, id(atu), id(btu)) # (1, 2, 3, 4) - (1, 2, 3)
2022
atu = atu + (4,)
2123
print "%s,%s | id %s,%s" % (atu, btu, id(atu), id(btu)) # (1, 2, 3, 4) - (1, 2, 3)
2224

@@ -28,5 +30,6 @@
2830
print "\n--- lists ---"
2931
ali = [1, 2, 3]
3032
bli = ali
33+
print "%s,%s | id %s,%s" % (ali, bli, id(ali), id(bli)) # [1, 2, 3, 4] - [1, 2, 3, 4]
3134
ali.append(4)
32-
print "%s,%s | id %s,%s" % (ali, bli, id(ali), id(bli)) # [1, 2, 3, 4] - [1, 2, 3, 4]
35+
print "%s,%s | id %s,%s" % (ali, bli, id(ali), id(bli)) # [1, 2, 3, 4] - [1, 2, 3, 4]

intro/o_control_structures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# statements
1212
# ----------------------
1313
print "\n--- if ---"
14-
if 10 == 5 + 5 or 20 == 10 + 10:
14+
if ((10 == 5 + 5 or 20 == 10 + 10) and
15+
True):
1516
print "correct"
1617
elif 10 == 20:
1718
print "this is wrong"

intro/q_dictionaries.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'''
22
@summary: Python Intro - Dictionaries
33
'''
4-
#key needs to be hashable -> immutable
4+
# key needs to be hashable -> immutable
55

66
# -----------------------
77
# Initialize empty
@@ -11,7 +11,7 @@
1111
# -----------------------
1212
# Init and populate
1313
# -----------------------
14-
dic = {"int":1, "st":"str", "li": [1, 2, 3],(2,3):"tuple value"}
14+
dic = {"int":1, "st":"str", "li": [1, 2, 3], (2, 3):"tuple value"}
1515

1616
# -----------------------
1717
# Extend (value can have any type)
@@ -32,25 +32,25 @@
3232
# Check for presence
3333
# -----------------------
3434
print dic.has_key("int") # True
35-
print "int" in dic # True
35+
print "int" in dic # True
3636

3737
# -----------------------
3838
# key has to be Immutable
3939
# -----------------------
40-
#dic={[0,1]:1} # TypeError: unhashable type: 'list'
40+
# dic={[0,1]:1} # TypeError: unhashable type: 'list'
4141

42-
# tuple is mutable
43-
dic={(0,1):1} # works
42+
# tuple is immutable
43+
dic = {(0, 1):1} # works
4444

4545
# -----------------------
4646
# Extracting
4747
# -----------------------
48-
dic={(0,1):1,"st":"abc","int":3}
49-
print dic.keys() #[(0, 1), 'int', 'st']
50-
print dic.values() # [1, 3, 'abc']
51-
print dic.items() # [((0, 1), 1), ('int', 3), ('st', 'abc')]
48+
dic = {(0, 1):1, "st":"abc", "int":3}
49+
print dic.keys() # [(0, 1), 'int', 'st']
50+
print dic.values() # [1, 3, 'abc']
51+
print dic.items() # [((0, 1), 1), ('int', 3), ('st', 'abc')]
5252

5353
print "-------------------------"
54-
dic = {"int":1, "st":"str", "li": [1, 2, 3],(2,3):"tuple value"}
54+
dic = {"int":1, "st":"str", "li": [1, 2, 3], (2, 3):"tuple value"}
5555
for key, value in dic.iteritems():
56-
print key,value
56+
print key, value

intro/slides/Python-Intro-Slide 1.JPG

213 Bytes
Loading

intro/slides/Python-Intro-Slide 2.JPG

989 Bytes
Loading

intro/slides/Python-Intro-Slide 3.JPG

5.11 KB
Loading

intro/slides/Python-Intro-Slide 4.JPG

14.8 KB
Loading

0 commit comments

Comments
 (0)