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

Here, we are going to demonstrate the '\()' to embed the value of the variable within the string in Swift programming language.
Last Updated : May 29, 2021

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

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

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

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 num, pi 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.

Swift Basic Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.