- Mar 02 Fri 2007 21:38
made by humans Eco Staple Free Stapler 無針訂書機
- Mar 02 Fri 2007 18:53
小丑 一
- Mar 02 Fri 2007 11:05
哈娜 驚悚系列 血咒語
- Mar 01 Thu 2007 18:50
小丑 楔子
- Mar 01 Thu 2007 14:13
程式語言 Python Loops/Branching
● Branching
making a decision to take one path or another.
● Conditions
Simple Condition: only one condition
Compound Condition: the combination of two or more conditions
● Logical Operator
◎ " not " Logical Operator
not True = False
not False = True
◎ " and " Logical Operator
True and True = True
True and False = False
False and True = False
False and False = False
Note: " and " can connect as much as conditions we need,
but as long as there's one False condition,
the compound condition is False
◎ " or " Logical Operator
True or True = True
True or False = True
False or True = True
False or False = False
Note: " or " can connect as much as conditions we need,
but as long as there's one True condition,
the compound condition is True
● Using " in " Operator
Uses in conditon statements
Input:
print "e" in "this is a test message"
print "ess" in "this is a test message"
Output:
True
True
● If, elif and else
if <condition> :
<statement>
elif <condition> :
<statement>
...
elif <condition> :
<statement>
else:
<statement>
Note:
Each consecutive lines of code is called a " BLOCK ".
Only one block will be executed.
If there's more then one condition is TRUE,
the block of the first true condition will be executed.
● while Loop
while <condition> :
<statement>
Note: While the condition is TRUE, the code will be executed repeatedly
● Comparison Operators
== equal to
!= not equal to
> greater then
< less then
>= greater then or equal to
<= less then or equal to
● International Infinite Loop, break and continue
◎ Input:
count = 0
while True:
count += 1
# end loop if count is greater then 7.
if count > 7:
break
# skip 2
if count == 2:
continue
print count
◎ Output:
1
3
4
5
6
7
Note:
The condition is always true, so this is a international infinite loop.
When the code hits " continue ", the loop skip the rest of the codes
and starts from the first line of the block.
When the code hits " break ", the loop ended.
● for Loop
for < i > in <main squence> :
<statement>
Note: A for loop repeats its loop body
for each element of the sequesce.
In this case, < i > is the varible
that represents the elements in the sequence
and <main squence> is the sequence.
- Mar 01 Thu 2007 12:33
程式語言 Python Numbers
● Numeric Types
Integers:Numbers without decimal point
34653456 or -4586u39
Floats:Numbers with decimal point
1111.00134 or -2342.0
● Mathematical Operators
Integers:
9 + 5 = 14
9 - 5 = 4
9 * 5 = 45
9 / 5 = 1
9 % 5 = 4
Floating-Point Numbers:
7.0 + 3.0 = 10.0
7.0 - 3.0 = 4.0
7.0 * 3.0 = 21.0
7.0 / 3.0 = 2.3333
7.0 % 3.0 = 1.0
Note:
as long as there's a floating-point number involved,
it's considered as a floating-point number calculation.
ie. 4 + 3.000 = 7.000
● Assignment with operators
x *= 5 -> x = x * 5
x /= 5 -> x = x / 5
x %= 5 -> x = x % 5
x += 5 -> x = x + 5
x -= 5 -> x = x - 5
● range()
◎ range(x):
returns a list with values from 0 to x-1
Input:
for i in range(10):
print i,
Output:
0 1 2 3 4 5 6 7 8 9
Note:
If we take away the comma ( , ) after the i,
then the output would be
0
1
2
3
4
5
6
7
8
9
◎ range(start, end, g)
returns a list with value from start to end-1 with gap of g
Input:
for i in range(10, 40, 5):
print i,
print "\n"
for j in range(10, 0, -1):
print j,
Output:
10 15 20 25 30 35
10, 9, 8, 7, 6, 5, 4, 3, 2, 1
- Mar 01 Thu 2007 11:52
程式語言 Python String
● Strings are immutable
● Crearing triple-quoted string
''' Here's where you want to put your string '''
● Using a Backslash
\' = '
\" = "
\\ = \
\a = bell
\b = backspace
\n = new line
\t = tab
● String with operators
"One" + "One" = "OneOne"
"One" * 5 = "OneOneOneOneOne"
● String Methods
◎ s = "coseTte Chiang"
s.upper() = "COSETTE CHIANG"
s.lower() = "cosette chiang"
s.swapcase() = "COSEtTE cHIANG"
s.capitalize() = "Cosette chiang"
s.title() = Cosette Chiang
◎ s = " ABCDE WXYZ "
s.strip() = "ABCDE WXYZ"
◎ s = "ABCDE ABCDE ABCDE"
s.replace("BCD", "MNO", 0) = "ABCDE ABCDE ABCDE"
s.replace("BCD", "MNO", 1) = "AMNOE ABCDE ABCDE"
s.replace("BCD", "MNO", 2) = "AMNOE AMNOE ABCDE"
Note: number is the limits for how many replacement
◎ s = "ABCDEFGHIJKLMNO"
s[3] = D
s[3:] = DEFGHIJKLMNO
s[4:9] = EFGHI
s[-3] = M
s[-3:] = MNO
Note: minus index meaning index counting from back
- Mar 01 Thu 2007 11:28
程式語言 Python Useful Statements
● raw_input("String")
Usage:
String name = raw_input("Hi. What's your name?")
then the program takes the user input and assign it to name
● Print Statement
Input:
print "ABCDEFG",
print "HIJKLMN"
Output:
"ABCDEFG HIJKLMN"
Note:
Notice the space between the first and second print statements
That is created by the comma ( , )
OR
Input:
print >> sys.stdout, "ABCDEFG"
Output:
"ABCDEFG"
Note:
Notice the 〝sys.stdout〞 after the 〝>>〞,
if we change the 〝stdout〞 to 〝stderr〞
then the message will be treat as an error message.
● Breaking up statements
When you need to break a line into two,
just use \ at any place where you can place a space
example:
print "XXXXXXXXXXXXXXXXXXXXXXXXXX" + "ZZZZZZZZZZZZZZZZZZZZZZZ"
is equals to
print "XXXXXXXXXXXXXXXXXXXXXXXXXX" + \
"ZZZZZZZZZZZZZZZZZZZZZZZ"
● Changing type
◎ float(x) Return a floating-point valu by converting x
float("10") = 10.0
◎ int(x) Return a integer value by converting x
int("10") = 10
◎ str(x) Return a string value by converting x
str(10) = "10"
● Using inport statement
If we need to use a module, we use import statement.
take module 〝random〞 for example:
import random
is all we need to type for using module random in our function
● len()
◎ String:
s = "012345678"
len(s) = 9
◎ List:
s = [0, 1, 2, 3, 4, 5, 6]
len(s) = 7
◎ Map:
s = {a:A, b:B, c:C, d:D}
len(s) = 4
- Mar 01 Thu 2007 11:22
程式語言 Python Comment
● Comment Example:
There are two ways to write a comment:
Start the comment with a #
OR
quote the whole string with three single quote ( ''' )
The following are the example for a three lines comment of the program:
# Hello World - Version 1.0 (Program Name - Version Numver)
# Demonstrates the print commend (Usage of the program)
# Cosette Chiang - 12/11/07 (Creater's Name - Date)
OR
''' Hello World - Version 1.0 (Program Name - Version Numver)
Demonstrates the print commend (Usage of the program)
Cosette Chiang - 12/11/07 (Creater's Name - Date)'''
- Mar 01 Thu 2007 11:19
程式語言 Python About Python
● Python is case-sensitive
例: print works ; PRINT doesn't
● Expressions & Statements:
例: Expression - "Game Over"
Statement - print "Game Over"
● Sequence:
Sequences fall into one of the two categories: mutable or immutable.
◎ Mutable means can be changed
◎ Immutable means can be changed
- Mar 01 Thu 2007 09:08
哈娜 驚悚系列 舞姬
- Jan 16 Tue 2007 08:55
Tim Deluxe - Less Talk, More Action!
A very very INTERESTING Song..
我想不少女孩應該有同樣的經歷 吧
原本好好的氣氛 被對方幾句笨話給打壞
是個完美的 Kisser 但是 Talk (Dirty?) 卻遠遠不及格
Boys. Less talk, more action!!
- Jan 16 Tue 2007 05:01
Re-ment 小道具 草莓小姐的家
- Jan 15 Mon 2007 05:14
Re-ment 小道具 女兒節
- Jan 14 Sun 2007 05:14
Re-ment 小道具 可愛動物餐具
- Jan 13 Sat 2007 05:14
Re-ment 小道具 童話國食器
- Jan 12 Fri 2007 05:14
Re-ment 小道具 文具
- Jan 11 Thu 2007 05:14
Re-ment 小道具 中國城雜貨店
- Jan 10 Wed 2007 05:14
Re-ment 小道具 夢見食器
- Jan 09 Tue 2007 05:14
Re-ment 小道具 後院雜物