Q:

Swift program to demonstrate the \'\\()\' to embed the value of the variable within the string

belongs to collection: Swift Basic Programs

0

Here, we will use '\()' to embed the value of the variable within the string and print the result on the console screen.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate the '\()' to embed the value of the variable within the string is given below. The given program is compiled and executed successfully.

// Swift program to demonstrate the '\()' to embed
// the value of variables within the string

var num:Int = 10;
var pi:Float = 3.14;
var str:String="Pi : \(pi)";

print("Num: \(num)");
print(str);

Output:

Num: 10
Pi : 3.14


...Program finished with exit code 0
Press ENTER to exit console.

Explanation:

In the above program, we created two variables numpi initialized with 10, 3.14 respectively. Then we created a string variable str, which is embedded the value of variable pi within the string initialized in the str variable. After that, we printed the result on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Swift Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Swift program to create a constant... >>
<< Swift program to demonstrate the escape sequences...