Python: Use double quotes to display strings
Python Basic: Exercise-130 with Solution
Double Quotes String Display
Write a Python program that uses double quotes to display strings.
Pictorial Presentation:
Sample Solution:
Python Code:
# Import the 'json' module to work with JSON data.
import json
# Create a Python dictionary with key-value pairs.
data = {'Alex': 1, 'Suresh': 2, 'Agnessa': 3}
# Use the 'json.dumps()' function to convert the dictionary to a JSON-formatted string and print it.
json_string = json.dumps(data)
print(json_string)
Sample Output:
{"Agnessa": 3, "Alex": 1, "Suresh": 2}
Flowchart:
Python Code Editor:
Previous: Write a Python program to add leading zeroes to a string.
Next: Write a Python program to split a variable length string into variables.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/python-basic-exercise-130.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics