ラベル python の投稿を表示しています。 すべての投稿を表示
ラベル python の投稿を表示しています。 すべての投稿を表示

2014年7月11日金曜日

python: lambda

my_list=range(10)
print filter(lambda x:x%2==0,my_list)

[0, 2, 4, 6, 8]

2014年7月9日水曜日

2014年7月8日火曜日

python: enumurate

choices = ['soccer', 'tennis', 'basketball', 'balleyball']

print 'Your choices are:'
for index, item in enumerate(choices):
    print index+1, item

2014年7月7日月曜日

python:range()

range(5) # => [0,1,2,3,4]
range(1,5) # => [1,2,3,4]
range(1,5,3) # => [1,4]

python_removal from list

list.pop(index)
list.remove(item)
del(list[index])

2014年7月2日水曜日

python function

def square_cal(length,width):
    return length*width

def square(length,width):
    if length==width:
        return  square_cal(length,width)
    else:
        return "Not square"

python %s %d %f %d

%s: 文字列
%d: 整数値
%f: 浮動小数点数
%x: 16進整数

python: raw_input()

name=raw_input("Your name is ")
print name

python: print "%.2f" %var

var=1.234567
print "%.2f" %var
print "%.3f" %var
print "%.4f" %var
print "%.5f" %var

1.23
1.235
1.2346
1.23457