Unit - Ii: Mr. Babu Illuri
Unit - Ii: Mr. Babu Illuri
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
you can have if statements inside if statements, this is
called nested if statements.
x = 41
if x > 10:
print("Above ten,")
if x > 20:
print("and also above 20!")
else:
print("but not above 20.")
Python has two primitive loop commands:
while loops
for loops
i = 1
while i < 6:
print(i)
i += 1
Note: remember to increment i, or else the loop will
continue forever.
With the break statement we can stop the loop even if the while condition is true:
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
JSON
JSON or JavaScript Object Notation is a lightweight
text-based open standard designed for human-readable
data interchange.
The JSON format was originally specified by Douglas
Crockford,.
The official Internet media type for JSON is
application/json. The JSON filename extension is
.json.
JSON stands for JavaScript Object Notation.
The format was specified by Douglas Crockford.
It was designed for human-readable data interchange.
It has been extended from the JavaScript scripting
language.
The filename extension is .json.
JSON Internet Media type is application/json.
The Uniform Type Identifier is public.json.
Uses of JSON
It is used while writing JavaScript based applications
that includes browser extensions and websites.
JSON format is used for serializing and
transmitting structured data over network
connection.
It is primarily used to transmit data between a server
and web applications.
Web services and APIs use JSON format to provide
public data.
It can be used with modern programming languages.
Simple Example in JSON
The following example shows how to use JSON to store information related to books
based on their topic and edition.
"
The process of encoding JSON is usually called serialization. This
Using minidom
In order to parse an XML document using minidom,
we must first import it from the xml.dom module. This
module uses the parse function to create a DOM object
from our XML file. The parse function has the
following syntax:
xml.dom.minidom.parse (filename_or_file[,parser[, bufsize]])
Here the file name can be a string containing the file
path or a file-type object. The function returns a
document, which can be handled as an XML type.
Thus, we can use the
function getElementByTagName() to find a specific
tag.
If we wanted to use an already-opened file, can just pass our
file object to parse like so:
Using ElementTree