"Python"의 두 판 사이의 차이

ph
이동: 둘러보기, 검색
1번째 줄: 1번째 줄:
==<code>is</code> and <code>==</code>==
+
=={{c|is}} and {{c|==}}==
<code>is</code> is identity testing, <code>==</code> is equality testing. what happens in your code would be emulated in the interpreter like this:
+
{{c|is}} is identity testing, {{c|==}} is equality testing. what happens in your code would be emulated in the interpreter like this:
 +
>>> a = 'pub'
 +
>>> b = ''.join(['p', 'u', 'b'])
 +
>>> a == b
 +
True
 +
>>> a is b
 +
False
 +
[http://stackoverflow.com/a/1504742/766330]
  
<source lang='python'>>>> a = 'pub'
 
>>> b = ''.join(['p', 'u', 'b'])
 
>>> a == b
 
True
 
>>> a is b
 
False</source>
 
  
[http://stackoverflow.com/a/1504742/766330]
+
 
 +
==Access index in {{c|for}} loop==
 +
for idx, val in enumerate(ints):
 +
    print(idx, val)
 +
[http://stackoverflow.com/a/522578/766330]
  
 
== ==
 
== ==

2017년 4월 10일 (월) 10:40 판

is and {{{1}}}

is is identity testing, {{{1}}} is equality testing. what happens in your code would be emulated in the interpreter like this:

>>> a = 'pub'
>>> b = .join(['p', 'u', 'b'])
>>> a == b
True
>>> a is b
False

[1]


Access index in for loop

for idx, val in enumerate(ints):
   print(idx, val)

[2]