-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path% code.py
More file actions
14 lines (11 loc) · 763 Bytes
/
% code.py
File metadata and controls
14 lines (11 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Program to demonstrate string formatting in Python using the '%' operator
# Step 1: Assigning values to variables
name = 'Parth' # The name of the student
course = 'Chemical Engg' # The course the student is enrolled in
age = 19 # The age of the student
# Step 2: Using string formatting to display the values
# The '%s' is used as a placeholder for strings, and '%d' is for integers.
print("name = %s and course = %s and age = %d" % (name, course, age))
# Step 3: Directly formatting values in the string without using variables
# Here, 'Anand', 'Mechanical Engg', and 20 are passed directly into the format placeholders.
print("name = %s and course = %s and age = %d" % ('Anand', 'Mechanical Engg', 20))