今さらPython

最初期のハロワ

編集

$ vim hello.py

hello.pyの内容

print ("こんにちはπ村")

実行

$ python hello.py
こんにちはπ村
$ _

複数行を書くには?

内容2(複数行)

改行で文は区切るが、セミコロンで区切る事もできる。

str = "こんにちは";str2 = "π村"
print (str+str2)

実行2

$ python hello.py
こんにちはπ村
$ _

ちなみに途中で改行もできるぞ。

内容3(複数行)

print (1+2+3+4+5+6+7+8+9+10)
print (1+2+3+4+5+6+ \
       7+8+9+10)

実行3

$ python hello2.py
55
55
$

ループや条件判定を入れてみるか。

内容

# coding: utf_8
# これはコメントだよ。
str = "こんにちは";str2 = "π村"
print (str+str2)

i = 0
n = 0
while i < 10:
   i = i + 1
   n = n + i
print (n)

ここに注意。

実行

$ python hello.py
こんにちはπ村
55
$

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2020-02-05 (水) 11:42:49