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

MyMemoWiki

「Python if for」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
(ページの作成:「==Pythoni if for== [Python] [http://python.secsup.org/?p=44 Python Osmosis] ===if,for=== Python 2.6.3 (r263rc1:75186, Oct 2 2009, 20:40:30) [MSC v.1500 32 bit (In…」)
 
1行目: 1行目:
 
==Pythoni if for==
 
==Pythoni if for==
[Python]
+
[[Python]]
[http://python.secsup.org/?p=44 Python Osmosis]
+
[[http://python.secsup.org/?p=44 Python Osmosis]]
 
===if,for===
 
===if,for===
  
15行目: 15行目:
 
      
 
      
 
  IDLE 2.6.3       
 
  IDLE 2.6.3       
  >>> x = int(raw_input("Please enter an integer: "))
+
  >>> x = int(raw_input("Please enter an integer: "))
 
  Please enter an integer: 42
 
  Please enter an integer: 42
  >>> type(x)
+
  >>> type(x)
  <type 'int'>
+
  &lt;type 'int'&gt;
  >>> if x < 0:
+
  &gt;&gt;&gt; if x &lt; 0:
 
  x = 0
 
  x = 0
 
  print 'Negative change to zero'
 
  print 'Negative change to zero'
30行目: 30行目:
 
   
 
   
 
  More
 
  More
  >>>
+
  &gt;&gt;&gt;
  >>> my_list = ['cat', 'window', 'defenestrate']
+
  &gt;&gt;&gt; my_list = ['cat', 'window', 'defenestrate']
  >>> for x in my_list:
+
  &gt;&gt;&gt; for x in my_list:
 
  print x, len(x)
 
  print x, len(x)
 
   
 
   
39行目: 39行目:
 
  window 6
 
  window 6
 
  defenestrate 12
 
  defenestrate 12
  >>>
+
  &gt;&gt;&gt;
  >>> for x in my_list[:]:
+
  &gt;&gt;&gt; for x in my_list[:]:
  if len(x) > 6:
+
  if len(x) &gt; 6:
 
  my_list.insert(0,x)
 
  my_list.insert(0,x)
 
   
 
   
 
 
 
 
  >>> my_list
+
  &gt;&gt;&gt; my_list
 
  ['defenestrate', 'cat', 'window', 'defenestrate']
 
  ['defenestrate', 'cat', 'window', 'defenestrate']

2020年2月15日 (土) 08:05時点における版

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