Explain and show code with dictionaries as used in Python b

Explain and show code with dictionaries as used in Python, (b) In what ways are they useful in developing web applications? Include and explain code examples. Explain and show Python code for using JSON.

Solution

Dictionaries in Python language:

Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is

enclosed in curly braces. An empty dictionary without any items is written with just two curly braces, like this: {}.

Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the

keys must be of an immutable data type such as strings, numbers, or tuples.

Accessing Values in Dictionary:

To access dictionary elements, you can use the familiar square brackets along with the key to obtain its value.

simple example

Output:

Advantage of using python for developing webappliacations:

You know how to write useful Python scripts, and now you want to show them off to the world… but how? Most

non-programmers won’t have any use for your .py script files. Programs like PyInstaller and cx_Freeze help turn

Python scripts into executable programs that run by themselves on different platforms without the need to use

Python to interpret the code. More and more, however, we’re seeing a trend away from “desktop”-based applications

and toward web applications that can be accessed and run through Internet browsers.

Python code for using JSON:

JSON Functions:

encode: Encodes the Python object into a JSON string representation.

Syntax:

Example:

output:

decode -- Decodes a JSON-endoded string into a Python object.

Syntax:

Example:

output:

 Explain and show code with dictionaries as used in Python, (b) In what ways are they useful in developing web applications? Include and explain code examples.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site