ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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.
Submitted by Nidhi, on May 29, 2021

Problem Solution:

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

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




Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.