In this program, we will illustrate the difference between a single quote string and a double-quoted string. The single quote string cannot interpolate the variables.
The source code to illustrate the difference between single quote string and double-quote string is given below. The given program is compiled and executed successfully.
# Ruby program to illustrate the difference between
# single quote string and double-quote string.
# Create variables to store
# string values.
MyStr1 = "Hello World";
MyStr2 = "Hello India";
puts 'Single quote string: #{Mystr1}';
puts "Double quote string: #{MyStr2}";
Output:
Single quote string: #{Mystr1}
Double quote string: Hello India
Explanation:
In the above program, we created two variables MyStr1, MyStr2 to store string values. Then we used single quote and double quote strings to interpolate string variables and found that we cannot interpolate string variables inside the single quote string.
Program/Source Code:
The source code to illustrate the difference between single quote string and double-quote string is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two variables MyStr1, MyStr2 to store string values. Then we used single quote and double quote strings to interpolate string variables and found that we cannot interpolate string variables inside the single quote string.
need an explanation for this answer? contact us directly to get an explanation for this answer