"함수 has value()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
7번째 줄: 7번째 줄:
==PHP==
==PHP==
{{참고|PHP in_array()}}
{{참고|PHP in_array()}}
<source lang='php'>
<syntaxhighlight lang='php'>
$d = ['a'=>100, 'b'=>200];
$d = ['a'=>100, 'b'=>200];
var_dump( in_array(100,$d) );
var_dump( in_array(100,$d) );
15번째 줄: 15번째 줄:
var_dump( in_array(999,$d) );
var_dump( in_array(999,$d) );
# bool(false)
# bool(false)
</source>
</syntaxhighlight>


==Python==
==Python==
[[분류: Python]]
[[분류: Python]]
{{참고|파이썬 has_value()}}
{{참고|파이썬 has_value()}}
<source lang='python'>
<syntaxhighlight lang='python'>
d = { "a": 100, "b": 200 }
d = { "a": 100, "b": 200 }
print( 100 in d.values() )
print( 100 in d.values() )
28번째 줄: 28번째 줄:
print( 999 in d.values() )
print( 999 in d.values() )
# False
# False
</source>
</syntaxhighlight>


==Ruby==
==Ruby==
[[분류: Ruby]]
[[분류: Ruby]]
{{참고|루비 .has_value}}
{{참고|루비 .has_value}}
<source lang='ruby'>
<syntaxhighlight lang='ruby'>
h = { "a" => 100, "b" => 200 }
h = { "a" => 100, "b" => 200 }
print h.has_value?(100)
print h.has_value?(100)
39번째 줄: 39번째 줄:
print h.has_value?(999)
print h.has_value?(999)
# false
# false
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:32 판

1 개요

함수/메소드 has_value()
in 연산자
  • dictionary에 해당 value가 있는지 판별하는 함수/메소드

2 PHP

$d = ['a'=>100, 'b'=>200];
var_dump( in_array(100,$d) );
# bool(true)
var_dump( in_array('100',$d) );
# bool(true)
var_dump( in_array(999,$d) );
# bool(false)

3 Python

d = { "a": 100, "b": 200 }
print( 100 in d.values() )
# True
print( '100' in d.values() )
# False
print( 999 in d.values() )
# False

4 Ruby

h = { "a" => 100, "b" => 200 }
print h.has_value?(100)
# true
print h.has_value?(999)
# false

5 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}