"String interpolation"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
8번째 줄: 8번째 줄:
==Bash==
==Bash==
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
name=Snoopy
name=Snoopy
echo "His name is $name"
echo "His name is $name"
# His name is Snoopy
# His name is Snoopy
</source>
</syntaxhighlight>


==Perl==
==Perl==
[[category: Perl]]
[[category: Perl]]
<source lang='Perl'>
<syntaxhighlight lang='Perl'>
my $apples = 4;
my $apples = 4;
print "I have $apples apples\n";
print "I have $apples apples\n";
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
$name = 'Snoopy';
$name = 'Snoopy';
echo "His name is $name";
echo "His name is $name";
// His name is Snoopy
// His name is Snoopy
</source>
</syntaxhighlight>


==Python==
==Python==
[[category: Python]]
[[category: Python]]
<source lang='Python'>
<syntaxhighlight lang='Python'>
apples = 4
apples = 4
print "I have %d apples" % apples
print "I have %d apples" % apples
39번째 줄: 39번째 줄:
# I have 4 apples
# I have 4 apples
# I have 4 apples
# I have 4 apples
</source>
</syntaxhighlight>


==Ruby==
==Ruby==
[[category: Ruby]]
[[category: Ruby]]
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
apples = 4
apples = 4
puts "I have #{apples} apples"
puts "I have #{apples} apples"
# I have 4 apples
# I have 4 apples
</source>
</syntaxhighlight>


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

2020년 11월 2일 (월) 02:31 기준 최신판

1 개요[ | ]

variable interpolation
string interpolation
문자열 인터폴레이션, 스트링 인터폴레이션
  • 문자열 중간에 있는 변수를 값으로 바꿈

2 Bash[ | ]

name=Snoopy
echo "His name is $name"
# His name is Snoopy

3 Perl[ | ]

my $apples = 4;
print "I have $apples apples\n";

4 PHP[ | ]

$name = 'Snoopy';
echo "His name is $name";
// His name is Snoopy

5 Python[ | ]

apples = 4
print "I have %d apples" % apples
print "I have {} apples".format(apples)
print "I have {a} apples".format(a=apples)
# I have 4 apples
# I have 4 apples
# I have 4 apples

6 Ruby[ | ]

apples = 4
puts "I have #{apples} apples"
# I have 4 apples

7 같이 보기[ | ]

8 참고[ | ]

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