トップ 差分 一覧 ping ソース 検索 ヘルプ PDF RSS ログイン

Python if for



目次



記事一覧

キーワード

Pythoni if for

[Python]
Python Osmosis

 if,for


Python 2.6.3 (r263rc1:75186, Oct  2 2009, 20:40:30) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
    
IDLE 2.6.3      
>>> x = int(raw_input("Please enter an integer: "))
Please enter an integer: 42
>>> type(x)
<type 'int'>
>>> if x < 0:
	x = 0
	print 'Negative change to zero'
elif  x == 0:
	print 'Zero'
elif  x == 1:
	print 'Single'
else:
	print 'More'

More
>>> 
>>> my_list = ['cat', 'window', 'defenestrate']
>>> for x in my_list:
	print x, len(x)

	
cat 3
window 6
defenestrate 12
>>> 
>>> for x in my_list[:]:
	if len(x) > 6:
		my_list.insert(0,x)

		
>>> my_list
['defenestrate', 'cat', 'window', 'defenestrate']



YAGI Hiroto (piroto@a-net.email.ne.jp)
twitter http://twitter.com/pppiroto

Copyright© 矢木 浩人 All Rights Reserved.