Python
Python (ぱいそん) は、イギリスの公共放送 BBC が製作したプログラミング言語。スパムやアンダースコア (_
) との相性が良い。なお同名のテレビ番組『空飛ぶモンティパイソン』は、どこかのオランダ人が制作したつまらない前衛芸術であり何の関係もない。
特徴[編集 ]
Pythonの数ある長所の中でも:
とくに有名なのは:
インデントを使った構文である
Pythonプログラマにとっては:
インデントは重要であるが:
呼吸がそうであるように普段はあなたが思うほど強く意識されない
__ただし__:
呼吸を忘れるとどうなるか想像がつくように:
インデントをまちがえると:
ひどい目にあうから:
気をつけて!
^
IndentationError: unindent does not match any outer indentation level
Pythonの速度[編集 ]
Pythonは数あるプログラミング言語の中でもとりわけ実行速度が速い。 以下はハーディ・ラマヌジャン数を出力するプログラムをそれぞれ C言語 と Python で書いたものである:
Cバージョン[編集 ]
#include<stdio.h> intmain(intargc,char*argv[]) { inta,b,c,d; for(a=1;a<=10000;a++){ for(b=a+1;b<=10000;b++){ for(c=1;c<=10000;c++){ for(d=c+1;d<=10000;d++){ if(a<c&&a*a*a+b*b*b==c*c*c+d*d*d){ printf("%d\n",a*a*a+b*b*b); return0; } } } } } }
Pythonバージョン[編集 ]
>>> print 1729
この例では、Cバージョンの実行に 11秒もかかっている (なお実験環境は Pentium4 の 2GHz、使用したコンパイラは gcc-3.3 である)。 これに対して、Pythonバージョンはわずか 0.01秒しかかかっていない。 いかに Python が効率のよいプログラミング言語であるかの証左といえよう。
なお、公平を期するために、Java によるバージョンも以下に提示しておく:
Javaバージョン[編集 ]
// HardyAndRamanujanNumberCalculatorOfMine.java // package com.my.own.domain.believe.me.this.is.mine; import logic.mathematics.calculator.standard.ordinary.normal.basic.StandardBasicNormalOrdinaryNumberCalculator; import universe.number.natural.unsigned.integer.standard.StandardIntegerFactory; import universe.number.natural.unsigned.integer.standard.StandardPositiveInteger; import universe.number.natural.unsigned.integer.standard.StandardCalculator; /** * Simple, concise, conprehesive and fully Object-Oriented example * of calculation of the first Hardy and Ramanujan Number. * */ @StandardCalculator(aspect = StandardCalculator.CALCULATE_AND_OUTPUT) public class HardyAndRamanujanNumberCalculatorOfMine extends StandardBasicNormalOrdinaryNumberCalculator { static final Integer MaxNumberForMainCalculationLoopOfMine = new Integer(100000); static public void main(String commandLineArgumentsAsOneBigAndLengthyList[]) { StandardIntegerFactory myIntegerFactoryForLoopCountersWhichStartFromOne = new StandardIntegerFactory(StandardIntegerFactory.POSITIVE_INTEGER | StandardIntegerFactory.SATISFY_ADDITIVE_PROPERTY); StandardPositiveInteger myIntegerNumberForTheFirstLoopCounter = myIntegerFactoryForLoopCountersWhichStartFromOne.createStandardInteger(StandardIntegerFactory.CREATE_STANDARD_INTEGER); StandardPositiveInteger myIntegerNumberForTheSecondLoopCounter = myIntegerFactoryForLoopCountersWhichStartFromOne.createStandardInteger(StandardIntegerFactory.CREATE_STANDARD_INTEGER); StandardPositiveInteger myIntegerNumberForTheThirdLoopCounter = myIntegerFactoryForLoopCountersWhichStartFromOne.createStandardInteger(StandardIntegerFactory.CREATE_STANDARD_INTEGER);
(省略されました...全てを読むにはここを押してください)
ええ、Perl版も欲しいって? しょうがないなぁ:
Perlバージョン[編集 ]
#!/usr/bin/perl use unstrict; while($a<1_00_00_){for($b=++$a;$b<eval("100*100");$b++){foreach$c(1..10__0_0__0){for($c+1..(100_00)){$d=$_;$a<$c&&$a*$a*$a+$b*$b*$b==$c*$c*$c+$d*$d*$d&&die($a*$a*$a+$b*$b*$b);}}}}
Pythonの実装[編集 ]
Pythonインタプリタには複数の実装が存在している。
- CPython - Colt Pythonの略。通常「Python」といえば357マグナムのコルト社製回転拳銃を指す。軽量化したCombat Pythonもある。
- Jython - 殺人マシン上に移植したもの。Pythonからライブラリを使って鉈を振り回させることができる。
- PyPy - PythonによるPythonのための、つまり、ぱいぱい。
Pythonを導入している有名悪徳企業 (アルファベット順)[編集 ]
- 悪の帝国 - どこかの料理番組に触発されて「Pythonの鉄人」なるパクリ番組をつくっている。[1]
- 金王国 - マスゲームの人民制御にPythonを使っているという。最近では国外逃亡者が大量に
yield
されているが、見つかるなり即座にガベージコレクションされているという。 - 他にも、マサチューセッツ工科大学(MIT)ではトイレの人工知能 ウォシュレットのプログラミングに長らくLISPが使われていたが、このたびPythonに移植されたという。MITは移植に反対したLisperの暴動のために 3日間閉鎖された。
Pythonコミュニティの有名人[編集 ]
- まつもとゆきひろ - 2000年ごろまで、USENET ニュースグループ comp.lang.python に出没していた。その熱心な投稿姿勢には誰もが引き込まれたという。
関連項目[編集 ]
外部リンク[編集 ]
- Guido van Robot (英語) - 世界征服プロジェクトのひとつ。Python 作者の Guido van Rossum をロボット化することにより、全人類を支配しようという壮大な試みはウィキペディアとも通じるところがある。
Print("動的型付け") : | LISP - JavaScript - VBScript - PHP - perl - Ruby - Python |
---|---|
Print(str("静的型付け")) : | BASIC - COBOL - C言語 - C++ - C# - D言語 - swift - HSP |
<p>マークアップ言語</p> : | HTML - CSS - MediaWiki |
++難解プログラミング言語++ : | Brainfuck - Grass - HQ9+ - lazy K - Pxem - 古代C言語 |
その他の言語 : | 手動 - 肉体言語 - DNA - Scratch |
構文等 : | Hello World - goto文 - 入れ子 - 再帰 - ヌル - クワイン |
UnBooks : | JavaScript入門 - 図解・今すぐわかるCSS |
関連項目 : | エクストリーム・プログラミング - 完全に理解した - フローチャート - オブジェクト指向 - プログラマー |