CSC1002 Week1 Overview
CSC1002 Week1 Overview
Laboratory
Kinley Lam
CSC1002/CUHK(SZ)/SSE
CSC 1002 Week 1
Programming background
editor & tools
hello world
past assignments at a glance
assessment
search for
“Free eBook”
Follow “Python Books” and then
“IntroductoryBooks” for a list of
reference books and free e-book(s)
CSC1002/CUHK(SZ) by Kinley Lam
Free ebooks via Python official website
• Modules
• Lists
• Dictionary
A C
B D
• List Comprehensions
Output
Block 1
Block 2
Block 3
Block 4
Block 5
conditional
Block 6 or controls
CSC1002/CUHK(SZ) by Kinley Lam
CSC1002/CUHK(SZ) by Kinley Lam
?
• 4th programmer:
• 2nd programmer: while (x>y) {
……;
while (x>y) { ……;
……; ……;
……; ……;
……;
……; ..…;
} ……;
}
which “if” is
“else” paired
with?
which “if” is
“else” paired
with?
Where
else can
we put it
??
if cond:
ret = val1
ret = val1 if cond else val2
else:
ret = val2
• position number
‘{0} {1} {2}’.format(‘apple’,’orange’,’grape’)
• keyword
‘{a} {o} {g}’.format( a=‘apple’, o=‘orange’, g=‘grape’ )
• ‘共有{}件样品失败{}件,失败率{}%’
• ‘총 {} 건의 실패 사례 {} 건, 실패율 {}%’
h e l l o w o r l d
. . . -8 -7 -6 -5 -4 -3 -2 -1
• use module “string” and try indexing and slicing with “ascii_lowercase”
• s = string.ascii_lowercase
• slicing: s[:], s[1:], s[:-1], s[1:-1], s[-6:], s[::2], s[::-1], s[1:10:-1]
• how to reverse a string using slicing? s[::-1]
0 1 2 3 4 . . . -2 -1
a b c d e f g h i j
step 1
[: step 2
:]
step 3
-1 -2 -3 -4 -5 . . . 1 0
j i h g f e d c b a
step -1
[: step -2
:]
step -3
result Remark
len(L) 3 length
1 in L true membership
for x in L: print(x, end=‘,’) 1,2,3, iteration
[x*x for x in L] [1,4,9] list comprehension
L.sort(reverse=True) [3,2,1] sort in reverse order