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

52번째 줄: 52번째 줄:
*[[puts]]
*[[puts]]
*[[string literal]]
*[[string literal]]
*[[변수 삽입]]


==참고 자료==
==참고 자료==
*http://en.wikipedia.org/wiki/Variable_interpolation
*http://en.wikipedia.org/wiki/Variable_interpolation
*http://en.wikipedia.org/wiki/String_interpolation
*http://en.wikipedia.org/wiki/String_interpolation

2014년 5월 31일 (토) 15:45 판

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 }}