More Related Content Similar to Hello World Python featuring GAE Similar to Hello World Python featuring GAE (20) Hello World Python featuring GAE2. a table of contents
• 自己紹介 • タプル
• なぜPython? • ディクショナリ
• なぜGAE? • if文
• Pythonの起動方法 • forループ
• Pythonの終了方法 • 関数
• HelloWorld • import
• 変数 • class
• 文字列 • hello world using GAE
• 数値
• リスト
3. 自己紹介
• maito kuwahara
• twitter @maito
• facebook https://www.facebook.com/maitokuwahara
• Blog http://temping-amagramer.blogspot.jp/
• 2006年∼2010年 日本ソフトウエア株式会社 SE(ColdFusion Oracle HTML JS CSS)
• 2010年∼ NHNJapan RIA(JavaScript PHP)
• 私生活では、、、 Python Objective-C PHP scheme Cなどなど。
• 本格的なプログラミングは、就職後。
6. Pythonの起動方法
• for mac テキスト
• ターミナルを起動
• pythonと入力し、Enter
• for windows
• コマンドプロンプトを起動
• cdコマンドでpython.exeファイルが
あるところまでディレクトリを移動
• pythonと入力し、Enter
8. Hello World
• print “hello world”と入力してEnter
>>> print "hello world"
hello world
• print “hello yoyogi.py”と入力してEnter
>>> print "hello yoyogi.py"
hello yoyogi.py
• print 3.14と入力してEnter
>>> print 3.14
3.14
9. 変数
• 文字列、数値、リストなどの値を格納する容器
ex)
>>> hoge = 'today is 3rd yoyogi.py'
>>> print hoge
today is 3rd yoyogi.py
• 変数名は、英数字かつ、先頭文字は、英単語
• 一部の名前については、使用不可
ex)
if、for、class、tryなどなど
10. 文字列
• 英単語、日本語、数字、記号などの文字の組み合わせ
• 変数に設定するときは、「‘」または「“」で囲む必要が有り
• 文字列同士を繋げたい場合は、「+」で接続
ex1)
>>> foo = 'greed'
>>> print foo
greed
ex2)
>>> foo = "greed " + " is " + " good "
>>> print foo
greed is good
ex3)
>>> foo = "I "
>>> bar = " study "
>>> hoge = " python"
>>> result = foo + bar + hoge
>>> print result
I study python
11. 数値
• 数字とカンマ「.」で構成
• 四則演算可能
• 文字列と連結は、NG
ex)
NG Pattern
>>> love = "akihabara" + 48
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
OK Pattern
>>> love = "akihabara " + str(48)
>>> print love
akihabara 48
12. リスト
• 文字、数値などで構成される集合体
• indexの指定により、リストの各要素を取得可能
• indexの先頭は、0
• 要素毎の更新可能
ex)
hoge = ["today","is",5,22]
>>> print hoge
['today', 'is', 5, 22]
>>> print hoge[1]
is
>>> hoge[2] = 6
>>> print hoge
['today', 'is', 6, 22]
13. タプル
• 文字、数値などで構成される集合体
• indexの指定により、リストの各要素を取得可能
• indexの先頭は、0
• 要素毎の更新不可
ex)
hoge = ("today","is",5,22)
>>> print hoge
('today', 'is', 5, 22)
>>> print hoge[1]
is
>>> hoge[2] = 6
>>> print hoge
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'tuple' object does not support item assignment
14. ディクショナリ
• key(キー)とvalue(文字、数値などで)構成される集合体
• keyの指定により、ディクショナリの各要素を取得可能
• 要素毎の更新可能
ex)
hoge = {'x':3,'y':"foo",'z':8}
>>> print hoge['x']
3
>>> hoge['y'] = 'bar'
>>> print hoge['y']
bar
15. if文
• ある条件をクリアーした場合に、特定の処理を実行
ex)
>>> hoge = [3,"foo",8]
>>> #最後に「:」が必要
>>> if hoge[0] > 3:
... #インデントを必ず行う
... print "check it"
... #3以下の場合に実行される
... else:
... print "come on"
...
come on
16. for文
• 繰り返し処理を行いたい場合に使用
ex1)
>>> hoge = [3,"foo",8]
>>> #最後に「:」が必要
>>> for i in hoge:
... print i
...
3
foo
8
ex2)
>>> #rangeは関数
>>> for i in range(3):
... print i
...
0
1
2
17. 関数
• ある特定の処理を実行してもらう機能
ex1)
>>> def foo(args):
... print args
...
>>> foo('call me')
call me
ex2)
>>> def foo(args):
... return "take" + args
...
>>> ret = foo(' my breath away')
>>> print ret
take my breath away
18. import
• ある特定のプログラムの集まりを使用可能な状態に変更
ex1)
>>> #乱数を出力するrandomパッケージをimport
>>> import random
>>> print random.random()
0.537642900846
ex2)
>>> #数字関連を扱うmathパッケージをimport
>>> import math
>>> math.ceil(1.45)
2.0
>>> #日付関連を扱うdatetimeパッケージをimport
>>> import datetime
>>> d = datetime.datetime.today()
>>> print d
2012-05-21 19:27:54.178793
19. class
• ある特定のプログラムの集合体
ex1)
>>> class hoge():
... def sayHallo(self,args):
... print "hello " + args
...
>>> foo = hoge()
>>> foo.sayHallo('yoyogi')
hello yoyogi
ex2)
>>> class hoge():
... def sayHallo(self):
... print "hello " + self.name
... def setName(self,args):
... self.name = args
...
>>> foo = hoge()
>>> foo.setName('tokyo')
>>> foo.sayHallo()
hello tokyo
Editor's Notes \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n