Page 243 - CTS - CSA TP - Volume 2
P. 243

COMPUTER SOFTWARE APPLICATION - CITS




           TASK 4: String Concatenation
           Code:
           # Example 4: String Concatenation

           # String variables
           first_name = “Neenu”
           last_name = “Sharma”
           # Concatenate strings
           full_name = first_name + “ “ + last_name

           # Print the full name
           print(“Full Name:”, full_name)
           Explanation:
           •  String variables (first_name and last_name) are concatenated using the + operator.
           •  The print statement displays the full name.

           Output:













           TASK 5: Formatted String
           Code:
           # Example 5: Formatted String

           # Format string with variables
           item = “Laptop”
           price = 1200.50
           # Print formatted string
           print(f”The {item} costs RS.{price:.2f}”)

           Explanation:
           •  A formatted string is created using an f-string, allowing variables (item and price) to be embedded directly into
              the string.

           •  The print statement displays the formatted string, including the price formatted with two decimal places.
           Output:

















                                                           228
                              CITS : IT & ITES - Computer Software Application - Exercise 122
   238   239   240   241   242   243   244   245   246   247   248