はじめてのPython(1)

文字列関係

# coding: UTF-8
print "Hello, World!"
print "2nd Hello","World"
#これはテストです

#複数行をそのまま出力
print """
<html>
    <head><title>This is Test </title</head>
    <body></body>
</html>
"""
#文字列の結合
print "test"+"Test"

#繰り返し
print "-"*40

#文字列長取得
print len("nanmojiarudesyouka")

#数値を文字列に変換
print str(7) + "月" + str(12) + "日"

#文字列のインデックスアクセス
str = "test"

print str[3]
print str[2]
print str[1]
print str[0]

#文字のスライス
#0 1 2 3 4 5 
#|A|B|C|D|E|
str2 = "ABCDE"
print str2[1:4]

出力

Hello, World!
2nd Hello World

<html>
    <head><title>This is Test </title</head>
    <body></body>
</html>

testTest
----------------------------------------
18
7月12日
t
s
e
t
BCD