ホームに戻る
 Pythonのサンプル

# coding: Shift_JIS
# python のサンプル

#
# 実行結果
#
#1
#0.5
#b
#abc1
#3
#40
#[10, 20, 30, 40, 60]
#(100, 200, 300, 500, 700)
#{'y': 2000, 'x': 1000, 'z': 3000}
#2
#False
#234end
#10
#20
#30
#40
#60
#list end
#True
#1:3
#1:3:5
#2:3:5
#

def f(x):
	return x + 1

seisuu = 1
print(seisuu)
syousuu = 0.5
print(syousuu)
mojiretu = 'abc'
print(mojiretu[1])
print(mojiretu + str(seisuu))
seisuu = 2
print(f(seisuu))
list = [10, 20, 30, 40]
print(list[-1])
list.append(60)
print(list[0:len(list)])
tuple = (100, 200, 300)
print(tuple + (500, 700))
dic = {'x': 1000, 'y': 2000}
dic['z'] = 3000
print(dic)
if seisuu == 2:
	print(seisuu)
	print(seisuu == 3)
else:
	print('seisuu != 2')
while seisuu < 5:
	print(seisuu, end='')
	seisuu += 1
else:
	print('end')
for x in list:
	print (x)
else:
	print('list end')
print(50 not in list)

class Point:
    def __init__(self, x, y = 3):
        self.x = x
        self.y = y

    def print(self):
        print(str(self.x) + ':' + str(self.y))

class Point3D(Point):
    def __init__(self, x, y = 3, z = 5):
        Point.__init__(self, x, y)
        self.z = z

    def print(self):
        print(str(self.x) + ':' + str(self.y)+ ':' + str(self.z))

p = Point(1)
p3d = [Point3D(1)] * 3 + [Point3D(2)] * 5

pa = [p, p3d[0], p3d[7]]
for x in pa:
	x.print()

inserted by FC2 system