SlideShare a Scribd company logo
1 of 14
Plan2:
Python Project (1)
Development of web applications for innovation café.

Tatsuya NAKAMURA
本プランの目的
• アプリケーション開発を通じて,プログラミングの基礎を習得
o Python,Web技術,データベース

[最終目標]
• イノベヤ用のWebアプリを開発
o 蔵書管理システム

2014/02/24

2
スケジュール(予定)
• 基礎編(2月〜4月)
o
o
1.
2.
3.

Webアプリ開発に必要な基礎知識を実際にプログラミングしながら学習
誰でも参加可能
Pythonの基礎(2回)
Webアプリの基礎(1回)
データベースの基礎(1回)

• 開発編(4月〜7月)
o イノベヤ用のWebアプリをグループで開発
o 事前希望者のみ参加可能

2014/02/24

3
今日の内容
• Pythonを知ろう!

[目次]
1.
2.
3.
4.
5.
6.

Pythonの概要
Pythonの基本
型とリテラル
制御構文
関数
クラス

2014/02/24

4
1. Pythonの概要
• 海外で人気のプログラミング言語
o
o
o
o

GoogleやAppleなどの大企業も使用
DropboxはPythonで開発
豊富な標準ライブラリと強力な外部ライブラリ
最近,日本でも利用者増

• 特徴
o インデントでブロックを表現(C言語では”{ }”で囲った部分)
o インタプリタ(コンパイル不要)
• インタラクティブシェル
o マルチプラットフォーム
• ほとんどのOSでPythonがインストール可能
2014/02/24

5
2. Pythonの基礎
• インデント(ブロック)
def main():
for i in range(1,4):
if i % 2 == 0:
print “%sは偶数です.” % i
else:
print “%sは奇数です.” % i

#
#
#
#

if __name__ == “__main__”:
main()

# コマンドラインからの実効かどうかの制御
# main()関数を呼び出す

インデントのレベル(深さ)で
ブロック,スコープを表現

mainという関数を定義
1から3までのループ処理
偶数かどうかのチェック
偶数の場合に出力

# 奇数の場合に出力

$ python sample1.py
1は奇数です.
2は偶数です.
3は奇数です.
2014/02/24

6
2. Pythonの基礎
• 入出力
name = raw_input("お名前は? ")
age = raw_input("何歳ですか? ")
print "こんにちは,%sさん(%s歳)" % (name, age)

日本語の入力は要対応

$ python sample2.py
お名前は? nakatatsu
何歳ですか? 23
こんにちは,nakatatsuさん(23歳)
2014/02/24

7
2. Pythonの基礎
• 変数
>>> spam = "ham"
>>> spam
'ham'
>>> egg
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
egg
NameError: name 'egg' is not defined

変数spamに
文字列hamを代入

未定義の変数を参照した場合
NameError
2014/02/24

8
2. Pythonの基礎
• デバッグ・トレースバック
def main():
x = "ほげ"
y = 123
concat(x, y)
def concat(a, b):
return a + b
if __name__ = "__main__":
main()

$ python sample3.py
Traceback (most recent call last):
File "sample3.py", line 10, in <module>
main()
File "sample3.py", line 4, in main
concat(x, y)
File "sample3.py", line 7, in concat
return a + b
TypeError: cannot concatenate 'str' and
'int' objects

2014/02/24

9
3. 型とリテラル
• Pythonは動的型付け言語なので,
代入されるデータの型に従って変数の型が決定
o 論理型(bool)
o 数値型(int, float, complex)
o シーケンス
• 文字列
• リスト
• タプル
• セット
o 辞書型
o None型
2014/02/24

10
4. 制御構文
# if文
a = 1
b = 2
if a < b:
print "True"
else:
print "False"

True
0
1
2
ok

# for文
for i in range(3):
print i
# while文
while a < b:
print "ok"
a += 1
2014/02/24

11
5. 関数
# 関数の宣言
def ham():
""" documentation """
return "egg“

egg

# 関数の呼び出し
bacon = ham()
print bacon

2014/02/24

12
6. クラス
• Pythonはオブジェクト指向プログラミングをサポート
# format
class CLASS_NAME:
""" documentation ""“
var1 = value
def method1(self, ...):
...
...
def method2(self, ...):
...
...

class Spam:
egg = 100
def ham():
return “ham"
spam = Spam()
print spam.egg
print spam.ham

100
ham

2014/02/24

13
6. クラス
• コンストラクタ
class Spam:
def __init__(self, ham, egg):
self.ham = ham
self.egg = egg
spam = Spam(1,2)

__init__はインスタンス作成時に
自動で呼び出される

• デストラクタ
class Spam:
def __del__(self):
print “deleted”
spam = Spam()
del spam

__del__はインスタンス削除時に
自動で呼び出される

2014/02/24

14

More Related Content

Viewers also liked

Final project raising south sudan - hannah risser
Final project   raising south sudan - hannah risserFinal project   raising south sudan - hannah risser
Final project raising south sudan - hannah risser
Hannah Risser
 
ALEX PEREZ - ÀFRICA DIGNA
ALEX PEREZ - ÀFRICA DIGNAALEX PEREZ - ÀFRICA DIGNA
ALEX PEREZ - ÀFRICA DIGNA
jotaemapemarina
 
Powerpoint alimentos elaborados.
Powerpoint alimentos elaborados.Powerpoint alimentos elaborados.
Powerpoint alimentos elaborados.
marquitush
 
김유나 페차쿠차
김유나 페차쿠차김유나 페차쿠차
김유나 페차쿠차
kyn9107
 
Extreme climates case study cards
Extreme climates case study cards Extreme climates case study cards
Extreme climates case study cards
Ellie Burton
 
Ackland Art Museum - Conservation of Scroll
Ackland Art Museum - Conservation of ScrollAckland Art Museum - Conservation of Scroll
Ackland Art Museum - Conservation of Scroll
acklandartmuseum
 
Using abbreviations
Using abbreviationsUsing abbreviations
Using abbreviations
Deny Mc
 

Viewers also liked (19)

What teen learners can learn from children
What teen learners can learn from childrenWhat teen learners can learn from children
What teen learners can learn from children
 
Ashu g lobal
Ashu g lobalAshu g lobal
Ashu g lobal
 
Reading Seriously Rocks
Reading Seriously RocksReading Seriously Rocks
Reading Seriously Rocks
 
Nike Love: Postcard to Ephesus
Nike Love: Postcard to EphesusNike Love: Postcard to Ephesus
Nike Love: Postcard to Ephesus
 
Final project raising south sudan - hannah risser
Final project   raising south sudan - hannah risserFinal project   raising south sudan - hannah risser
Final project raising south sudan - hannah risser
 
Website tips & tricks
Website tips & tricksWebsite tips & tricks
Website tips & tricks
 
SMART International Symposium for Next Generation Infrastructure: Modelling I...
SMART International Symposium for Next Generation Infrastructure: Modelling I...SMART International Symposium for Next Generation Infrastructure: Modelling I...
SMART International Symposium for Next Generation Infrastructure: Modelling I...
 
ALEX PEREZ - ÀFRICA DIGNA
ALEX PEREZ - ÀFRICA DIGNAALEX PEREZ - ÀFRICA DIGNA
ALEX PEREZ - ÀFRICA DIGNA
 
El verbo ir - Presentación
El verbo ir - PresentaciónEl verbo ir - Presentación
El verbo ir - Presentación
 
Brand moi(2)
Brand moi(2)Brand moi(2)
Brand moi(2)
 
Powerpoint alimentos elaborados.
Powerpoint alimentos elaborados.Powerpoint alimentos elaborados.
Powerpoint alimentos elaborados.
 
Understanding Tomorrow, Acting Today
Understanding Tomorrow, Acting TodayUnderstanding Tomorrow, Acting Today
Understanding Tomorrow, Acting Today
 
UIB Value Proposition US
UIB Value Proposition USUIB Value Proposition US
UIB Value Proposition US
 
김유나 페차쿠차
김유나 페차쿠차김유나 페차쿠차
김유나 페차쿠차
 
Extreme climates case study cards
Extreme climates case study cards Extreme climates case study cards
Extreme climates case study cards
 
Ackland Art Museum - Conservation of Scroll
Ackland Art Museum - Conservation of ScrollAckland Art Museum - Conservation of Scroll
Ackland Art Museum - Conservation of Scroll
 
Final pink panthers_03_30
Final pink panthers_03_30Final pink panthers_03_30
Final pink panthers_03_30
 
Proyecto ingles
Proyecto inglesProyecto ingles
Proyecto ingles
 
Using abbreviations
Using abbreviationsUsing abbreviations
Using abbreviations
 

Similar to PythonProject(1)

オープンデータのためのスクレイピング
オープンデータのためのスクレイピングオープンデータのためのスクレイピング
オープンデータのためのスクレイピング
直之 伊藤
 

Similar to PythonProject(1) (20)

Python学習奮闘記#07 webapp
Python学習奮闘記#07 webappPython学習奮闘記#07 webapp
Python学習奮闘記#07 webapp
 
201110 02 Polytech center 2
201110 02 Polytech center 2201110 02 Polytech center 2
201110 02 Polytech center 2
 
2.プログラミングの基礎
2.プログラミングの基礎2.プログラミングの基礎
2.プログラミングの基礎
 
PHPプログラミングのIPv6対応の実際
PHPプログラミングのIPv6対応の実際PHPプログラミングのIPv6対応の実際
PHPプログラミングのIPv6対応の実際
 
今時のオンプレなgithubクローン環境構築
今時のオンプレなgithubクローン環境構築今時のオンプレなgithubクローン環境構築
今時のオンプレなgithubクローン環境構築
 
オープンデータのためのスクレイピング
オープンデータのためのスクレイピングオープンデータのためのスクレイピング
オープンデータのためのスクレイピング
 
Project Management Plan Sample Creative Content Lab Tokyo
Project Management Plan Sample Creative Content Lab TokyoProject Management Plan Sample Creative Content Lab Tokyo
Project Management Plan Sample Creative Content Lab Tokyo
 
20150227 イタンジプログラミング講座テキスト第4回
20150227 イタンジプログラミング講座テキスト第4回20150227 イタンジプログラミング講座テキスト第4回
20150227 イタンジプログラミング講座テキスト第4回
 
鳥取python勉強会 第2回
鳥取python勉強会 第2回鳥取python勉強会 第2回
鳥取python勉強会 第2回
 
.NET Coreとツール類の今
.NET Coreとツール類の今.NET Coreとツール類の今
.NET Coreとツール類の今
 
20150212 イタンジプログラミング講座テキスト第2回
20150212 イタンジプログラミング講座テキスト第2回20150212 イタンジプログラミング講座テキスト第2回
20150212 イタンジプログラミング講座テキスト第2回
 
厳研Python講座1回目
厳研Python講座1回目厳研Python講座1回目
厳研Python講座1回目
 
Twitterにおける即時話題推定技術「どたばたかいぎ」の開発
Twitterにおける即時話題推定技術「どたばたかいぎ」の開発Twitterにおける即時話題推定技術「どたばたかいぎ」の開発
Twitterにおける即時話題推定技術「どたばたかいぎ」の開発
 
ChainerMNをDocker containerで動かす
ChainerMNをDocker containerで動かすChainerMNをDocker containerで動かす
ChainerMNをDocker containerで動かす
 
2017823 pythonを始めよう
2017823 pythonを始めよう2017823 pythonを始めよう
2017823 pythonを始めよう
 
Softlayer勉強会#2
Softlayer勉強会#2Softlayer勉強会#2
Softlayer勉強会#2
 
HTML5スマートフォン業務アプリ開発セミナー(応用)テキストの抜粋
HTML5スマートフォン業務アプリ開発セミナー(応用)テキストの抜粋HTML5スマートフォン業務アプリ開発セミナー(応用)テキストの抜粋
HTML5スマートフォン業務アプリ開発セミナー(応用)テキストの抜粋
 
コロナ禍の開発勉強会~社内教育ツールの開発と実装
コロナ禍の開発勉強会~社内教育ツールの開発と実装コロナ禍の開発勉強会~社内教育ツールの開発と実装
コロナ禍の開発勉強会~社内教育ツールの開発と実装
 
Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )Python for Beginners ( #PyLadiesKyoto Meetup )
Python for Beginners ( #PyLadiesKyoto Meetup )
 
20140629 firefoxos-devenv
20140629 firefoxos-devenv20140629 firefoxos-devenv
20140629 firefoxos-devenv
 

PythonProject(1)