| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Python if for

提供: MyMemoWiki
2020年2月16日 (日) 04:31時点におけるPiroto (トーク | 投稿記録)による版
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

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']