Ii MSC Python Unit I Notes
Ii MSC Python Unit I Notes
UNIT - I: OVERVIEW
Introduction to Python: Features of Python - How to Run Python – Identifiers – Reserved
Keywords - Variables - Comments in Python - Indentation in Python - Multi-Line Statements -
Multiple Statement Group (Suite) – Quotes in Python - Input, Output and Import Functions -
Operators. Data Types and Operations: Numbers-Strings-List-Tuple-Set-Dictionary-Data type
conversion.
UNIT - II: FLOW CONTROL & FUNCTIONS
Flow Control: Decision Making-Loops-Nested Loops-Types of Loops. Functions: Function
Definition-Function Calling - Function Arguments - Recursive Functions - Function with
more than one return value.
UNIT - III: MODULES, PACKAGES AND FILE HANDLING
Modules and Packages: Built-in Modules - Creating Modules - import Statement – Locating
Modules - Namespaces and Scope - The dir() function - The reload() function - Packages in Python -
Date and Time Modules. File Handling: Opening a File - Closing a File - Writing to a File – Reading
from a File - File Methods - Renaming a File - Deleting a File – Directories in Python.
UNIT - IV: OBJECT ORIENTED PROGRAMMING
Class Definition - Creating Objects - Built-in Attribute Methods - Built-in Class Attributes -
Destructors in Python Encapsulation - Data Hiding- Inheritance - Method Overriding Polymorphism.
Exception Handling: Built-in Exceptions - Handling Exceptions – Exception with Arguments- Raising
Exception - User-defined Exception - Assertions in Python
UNIT - V: REGULAR EXPRESSIONS & WEB APPLICATIONS
Regular Expressions: The match() function - The search() function - Search and Replace -
Regular Expression Modifiers: Option Flags - Regular Expression Patterns – Character Classes -
Special Character Classes - Repetition Cases - findall() method - compile() method. Web Application
Framework- Django Architecture- Starting development- Case Study: Blogging App.
TEXTS
1. Jeeva Jose and P. SojanLal, “Introduction to Computing and Problem Solving with
Python”, Khanna Book Publising Co. (P) Ltd., 2016.
2. ArshdeepBahga, Vijay Madisetti, “Cloud Computing: A Hands – On Approach”
Universities press (India) Pvt. limited016.
PROGRAMMING USING PYTHON
CONTENTS
UNIT - 1
PAGE
CHAPTER TOPIC’S
NO
1.1 Python 1
1.1.1 Characteristics of Python 1
1.1.2 Applications of Python 2
1.1.3 Features of Python 2
1.2 Python Basic Syntax 4
1.2.1 Python First Program 4
1.3 Python identifier 5
1.1 Python
Python is Interactive − You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
It can be used as a scripting language or can be compiled to byte-code for building large
applications.
It provides very high-level dynamic data types and supports dynamic type checking.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
Python is one of the most widely used language over the web.
Easy-to-learn − Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
Easy-to-read − Python code is more clearly defined and visible to the eyes.
A broad standard library − Python's bulk of the library is very portable and cross-
platform compatible on UNIX, Windows, and Macintosh.
Interactive Mode − Python has support for an interactive mode which allows interactive
testing and debugging of snippets of code.
Portable − Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
Extendable − You can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.
GUI Programming − Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC, Macintosh,
and the X Window system of Unix.
Scalable − Python provides a better structure and support for large programs than shell
scripting.
Easy-to-learn − Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
2 DEPARTMENT OF COMPUTER SCIENCE-RCASW-MS.K.RATHI DEVI
DCS33-PROGRAMMING USING PYTHON UNIT I
Easy-to-read − Python code is more clearly defined and visible to the eyes.
A broad standard library − Python's bulk of the library is very portable and cross-
platform compatible on UNIX, Windows, and Macintosh.
Interactive Mode − Python has support for an interactive mode which allows interactive
testing and debugging of snippets of code.
Portable − Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
Extendable − You can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.
GUI Programming − Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC, Macintosh,
and the X Window system of Unix.
Scalable − Python provides a better structure and support for large programs than shell
scripting.
Python has a big list of good features, few are listed below −
It can be used as a scripting language or can be compiled to byte-code for building large
applications.
It provides very high-level dynamic data types and supports dynamic type checking.
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.
For example -
1. def func():
2. statement 1
3. statement 2
4. …………………
5. …………………
6. statement N
In the above example, the statements that are same level to right belong to the function.
Generally, we can use four whitespaces to define indentation.
Python provides the facility to execute the code using few lines.
For example - Suppose we want to print the "Hello World" program in Java; it will take three
lines to print it.
A Python identifier is a name used to identify a variable, function, class, module or other
object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by
zero or more letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and % within identifiers.
Python is a case sensitive programming language.
Thus, Manpower and manpower are two different identifiers in Python.
Class names start with an uppercase letter. All other identifiers start with a lowercase
letter.
Starting an identifier with a single leading underscore indicates that the identifier is
private.
Starting an identifier with two leading underscores indicates a strongly private identifier.
If the identifier also ends with two trailing underscores, the identifier is a language-
defined special name.
Reserved words (also called keywords) are defined with predefined meaning and syntax
in the language. These keywords have to be used to develop programming instructions.
Reserved words can’t be used as identifiers for other programming elements like name of
variable, function etc.
Following is the list of reserved keywords in Python 3
def if raise
del import return
elif in True
else is try
Python 3 has 33 keywords while Python 2 has 30. The print has been removed from
Python 2 as keyword and included as built-in function.
1.5 Variables
Variables are nothing but reserved memory locations to store values. This means that
when you create a variable you reserve some space in memory.
Based on the data type of a variable, the interpreter allocates memory and decides what
can be stored in the reserved memory.
Therefore, by assigning different data types to variables, you can store integers,
decimals or characters in these variables.
Python variables do not need explicit declaration to reserve memory space. The
declaration happens automatically when you assign a value to a variable.
The operand to the left of the = operator is the name of the variable and the operand to
the right of the = operator is the value stored in the variable.
For example
#!/usr/bin/python
print counter
print miles
print name
Here, 100, 1000.0 and "John" are the values assigned to counter, miles, and name variables,
respectively.
100
1000.0
John
For example − a = b = c = 1
Here, an integer object is created with the value 1, and all three variables are assigned to
the same memory location. You can also assign multiple objects to multiple variables.
Here, two integer objects with values 1 and 2 are assigned to variables a and b
respectively, and one string object with the value "john" is assigned to the variable c.
For example, a person's age is stored as a numeric value and his or her address is stored as
alphanumeric characters. Python has various standard data types that are used to define
the operations possible on them and the storage method for each of them.
Numbers
String
List
Tuple
Dictionary
Python Numbers
Number data types store numeric values. Number objects are created when you assign a
value to them. For example −
var1 = 1
var2 = 10
You can also delete the reference to a number object by using the del statement.
You can delete a single object or multiple objects by using the del statement.
long (long integers, they can also be represented in octal and hexadecimal)
Examples
Python allows you to use a lowercase l with long, but it is recommended that you use only
an uppercase L to avoid confusion with the number 1. Python displays long integers with
an uppercase L.
Python Strings
Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting
at 0 in the beginning of the string and working their way from -1 at the end.
9 DEPARTMENT OF COMPUTER SCIENCE-RCASW-MS.K.RATHI DEVI
DCS33-PROGRAMMING USING PYTHON UNIT I
The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition
operator. For example −
#!/usr/bin/python
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
Python Lists
Lists are the most versatile of Python's compound data types. A list contains items
separated by commas and enclosed within square brackets ([]).
To some extent, lists are similar to arrays in C. One difference between them is that all
the items belonging to a list can be of different data type.
The values stored in a list can be accessed using the slice operator ([ ] and [:]) with
indexes starting at 0 in the beginning of the list and working their way to end -1. The
plus (+) sign is the list concatenation operator, and the asterisk (*) is the repetition
operator.
For example
#!/usr/bin/python
Python Tuples
A tuple is another sequence data type that is similar to the list. A tuple consists of a number
of values separated by commas. Unlike lists, however, tuples are enclosed within
parentheses.
Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed,
while tuples are enclosed in parentheses ( ( ) ) and cannot be updated.
For example
#!/usr/bin/python
The following code is invalid with tuple, because we attempted to update a tuple, which is not
allowed. Similar case is possible with lists −
#!/usr/bin/python
Python Dictionary
Python's dictionaries are kind of hash table type. They work like associative arrays or
hashes found in Perl and consist of key-value pairs.
A dictionary key can be almost any Python type, but are usually numbers or strings.
Values, on the other hand, can be any arbitrary Python object.
Dictionaries are enclosed by curly braces ({ }) and values can be assigned and accessed
using square braces ([]).
For example
#!/usr/bin/python
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
This is one
This is two
{'dept': 'sales', 'code': 6734, 'name': 'john'}
['dept', 'code', 'name']
Dictionaries have no concept of order among elements. It is incorrect to say that the elements
are "out of order"; they are simply unordered.
It perform conversions between the built-in types. To convert between types, you simply
use the type name as a function.
There are several built-in functions to perform conversion from one data type to another.
These functions return a new object representing the converted value.
1
int(x [,base])
2
long(x [,base] )
3
float(x)
4
complex(real [,imag])
5
str(x)
6
repr(x)
7
eval(str)
8
tuple(s)
Converts s to a tuple.
9
list(s)
Converts s to a list.
10
set(s)
Converts s to a set.
11
dict(d)
12
frozenset(s)
13
chr(x)
14
unichr(x)
15
ord(x)
16
hex(x)
17
oct(x)
A hash sign (#) that is not inside a string literal begins a comment.
All characters after the # and up to the end of the physical line are part of the comment
and the Python interpreter ignores them.
Example
#!/usr/bin/python
# First comment
Output
Hello, Python!
You can type a comment on the same line after a statement or expression −
# This is a comment.
# This is a comment, too.
# This is a comment, too.
# I said that already.
Following triple-quoted string is also ignored by Python interpreter and can be used as a
multiline comments −
'''
This is a multiline
comment.
'''
Python provides no braces to indicate blocks of code for class and function definitions or
flow control.
Blocks of code are denoted by line indentation, which is rigidly enforced.
The number of spaces in the indentation is variable, but all statements within the block
must be indented the same amount.
For example
if True:
print "True"
else:
print "False"
if True:
print "Answer"
print "True"
else:
print "Answer"
print "False"
Thus, in Python all the continuous lines indented with same number of spaces would form a
block. The following example has various statement blocks −
#!/usr/bin/python
import sys
try:
except IOError:
sys.exit()
if file_text == file_finish:
file.close
break
file.write(file_text)
file.write("\n")
file.close()
if len(file_name) == 0:
sys.exit()
try:
except IOError:
sys.exit()
file_text = file.read()
file.close()
print file_text
Statements in Python typically end with a new line. Python does, however, allow the use
of the line continuation character (\) to denote that the line should continue. For example −
total = item_one + \
item_two + \
item_three
Statements contained within the [], {}, or () brackets do not need to use the line continuation
character. For example −
A group of individual statements, which make a single code block are called suites in
Python. Compound or complex statements, such as if, while, def, and class require a header
line and a suite.
Header lines begin the statement (with the keyword) and terminate with a colon (: ) and are
followed by one or more lines which make up the suite.
Example
if expr1==True:
stmt1
stmt2
elif expr2==True:
stmt3
stmt4
else:
stmt5
stmt6
while expr==True:
stmt1
stmt2
Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long
as the same type of quote starts and ends the string.
The triple quotes are used to span the string across multiple lines. For example, all the following
are legal −
word = 'word'
sentence = "This is a sentence."
paragraph = """This is a paragraph. It is
made up of multiple lines and sentences."""
The basic I/O functions available in Python. For more functions, please refer to standard
Python documentation.
21 DEPARTMENT OF COMPUTER SCIENCE-RCASW-MS.K.RATHI DEVI
DCS33-PROGRAMMING USING PYTHON UNIT I
The simplest way to produce output is using the print statement where you can pass zero
or more expressions separated by commas.
This function converts the expressions you pass into a string and writes the result to
standard output as follows −
#!/usr/bin/python
Python provides two built-in functions to read a line of text from standard input, which
by default comes from the keyboard. These functions are −
raw_input
input
The raw_input([prompt]) function reads one line from standard input and returns it as a
string (removing the trailing newline).
#!/usr/bin/python
This prompts you to enter any string and it would display same string on the screen. When I
typed "Hello Python!", its output is like this −
The input([prompt]) function is equivalent to raw_input, except that it assumes the input is a
valid Python expression and returns the evaluated result to you.
#!/usr/bin/python
This would produce the following result against the entered input −
Reading and writing to the standard input and output. Now, we will see how to use
actual data files.
Python provides basic functions and methods necessary to manipulate files by default.
You can do most of the file manipulation using a file object.
Before you can read or write a file, you have to open it using Python's built-
in open() function.
This function creates a file object, which would be utilized to call other support methods
associated with it.
Syntax
file object = open(file_name [, access_mode][, buffering])
file_name − The file_name argument is a string value that contains the name of the file
that you want to access.
access_mode − The access_mode determines the mode in which the file has to beopened,
i.e., read, write, append, etc. A complete list of possible values is given below inthe table.
This is optional parameter and the default file access mode is read (r).
buffering − If the buffering value is set to 0, no buffering takes place. If the buffering
value is 1, line buffering is performed while accessing a file. If you specify the buffering
value as an integer greater than 1, then buffering action is performed with the indicated
buffer size. If negative, the buffer size is the system default(default behavior).
1 R:Opens a file for reading only. The file pointer is placed at the beginning of the file. This
is the default mode.
2 Rb: Opens a file for reading only in binary format. The file pointer is placed at the
beginning of the file. This is the default mode.
3 r+: Opens a file for both reading and writing. The file pointer placed at the beginning of
the file.
4
rb+:Opens a file for both reading and writing in binary format. The file pointer placed at
the beginning of the file.
5
W:Opens a file for writing only. Overwrites the file if the file exists. If the file does not
exist, creates a new file for writing.
6 wb: Opens a file for writing only in binary format. Overwrites the file if the file exists. If
the file does not exist, creates a new file for writing.
7
w+: Opens a file for both writing and reading. Overwrites the existing file if the file exists.
If the file does not exist, creates a new file for reading and writing.
8
wb+:Opens a file for both writing and reading in binary format. Overwrites the existing
file if the file exists. If the file does not exist, creates a new file for reading and writing.
9 a :Opens a file for appending. The file pointer is at the end of the file if the file exists. That
is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
10 ab :Opens a file for appending in binary format. The file pointer is at the end of the file if
the file exists. That is, the file is in the append mode. If the file does not exist, it creates a
new file for writing.
11
a+ :Opens a file for both appending and reading. The file pointer is at the end of the file if
the file exists. The file opens in the append mode. If the file does not exist, it creates a new
file for reading and writing.
12
ab+ : Opens a file for both appending and reading in binary format. The file pointer is at the
end of the file if the file exists. The file opens in the append mode. If the file does not exist,
it creates a new file for reading and writing.
Once a file is opened and you have one file object, you can get various information
related to that file.
4 file.softspace: Returns false if space explicitly required with print, true otherwise.
Example
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
print "Closed or not : ", fo.closed
print "Opening mode : ", fo.mode
print "Softspace flag : ", fo.softspace
The close() method of a file object flushes any unwritten information and closes the file
object, after which no more writing can be done.
Python automatically closes a file when the reference object of a file is reassigned to
another file. It is a good practice to use the close() method to close a file.
Syntax
fileObject.close()
Example
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
The file object provides a set of access methods to make our lives easier. We would see
how to use read() and write() methods to read and write files.
The write() method writes any string to an open file. It is important to note that Python
strings can have binary data and not just text.
The write() method does not add a newline character ('\n') to the end of the string −
Syntax
fileObject.write(string)
Here, passed parameter is the content to be written into the opened file.
Example
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "wb")
fo.write( "Python is a great language.\nYeah its great!!\n")
The above method would create foo.txt file and would write given content in that file and finally
it would close that file. If you would open this file, it would have following content.
The read() method reads a string from an open file. It is important to note that Python
strings can have binary data. apart from text data.
Syntax
fileObject.read([count])
Here, passed parameter is the number of bytes to be read from the opened file. This method
starts reading from the beginning of the file and if count is missing, then it tries to read as much
as possible, maybe until the end of file.
Example
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "r+")
str = fo.read(10);
print "Read String is : ", str
# Close opend file
fo.close()
File Positions
The tell() method tells you the current position within the file; in other words, the next
read or write will occur at that many bytes from the beginning of the file.
The seek(offset[, from]) method changes the current file position. The offset argument
indicates the number of bytes to be moved. The from argument specifies the reference
position from where the bytes are to be moved.
If from is set to 0, it means use the beginning of the file as the reference position and 1
means use the current position as the reference position and if it is set to 2 then the end
of the file would be taken as the reference position.
Example
#!/usr/bin/python
# Open a file
fo = open("foo.txt", "r+")
str = fo.read(10)
print "Read String is : ", str
Python os module provides methods that help you perform file-processing operations,
such as renaming and deleting files.
To use this module you need to import it first and then you can call any related functions.
The rename() method takes two arguments, the current filename and the new filename.
Syntax
os.rename(current_file_name, new_file_name)
Example
#!/usr/bin/python
import os
You can use the remove() method to delete files by supplying the name of the file to be deleted
as the argument.
Syntax
os.remove(file_name)
Example
#!/usr/bin/python
import os
Directories in Python
All files are contained within various directories, and Python has no problem handling
these too. The os module has several methods that help you create, remove, and change
directories.
You can use the mkdir() method of the os module to create directories in the current
directory.
You need to supply an argument to this method which contains the name of the directory
to be created.
Syntax
os.mkdir("newdir")
Example
#!/usr/bin/python
import os
You can use the chdir() method to change the current directory. The chdir() method takes
an argument, which is the name of the directory that you want to make the current
directory.
Syntax
os.chdir("newdir")
Example
#!/usr/bin/python
import os
Syntax
os.getcwd()
Example
#!/usr/bin/python
import os
The rmdir() method deletes the directory, which is passed as an argument in the method.
Syntax
os.rmdir('dirname')
Example
Following is the example to remove "/tmp/test" directory. It is required to give fully qualified
name of the directory, otherwise it would search for that directory in the current directory.
#!/usr/bin/python
import os
There are three important sources, which provide a wide range of utility methods to handle
and manipulate files & directories on Windows and UNIX operating systems. They are as
follows −
File Object Methods: The file object provides functions to manipulate files.
1.12 Operators:
Operators are the constructs which can manipulate the value of operands.
Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator.
Arithmetic Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
// Floor Division - The division of operands where 9//2 = 4 and 9.0//2.0 = 4.0, -
the result is the quotient in which the digits after 11//3 = -4, -11.0//3 = -4.0
the decimal point are removed. But if one of the
operands is negative, the result is floored, i.e.,
rounded away from zero (towards negative
infinity) −
These operators compare the values on either sides of them and decide the relation among them.
They are also called Relational operators.
== If the values of two operands are equal, then the (a == b) is not true.
condition becomes true.
<> If values of two operands are not equal, then (a <> b) is true. This is similar to !=
condition becomes true. operator.
> If the value of left operand is greater than the (a > b) is not true.
value of right operand, then condition becomes
true.
< If the value of left operand is less than the value (a < b) is true.
of right operand, then condition becomes true.
>= If the value of left operand is greater than or (a >= b) is not true.
equal to the value of right operand, then
condition becomes true.
<= If the value of left operand is less than or equal to (a <= b) is true.
the value of right operand, then condition
becomes true.
= Assigns values from right side operands to left side operand c=a+b
assigns
value of a
+ b into c
+= Add AND It adds right operand to the left operand and assign the result to left c += a is
equivalent
operand to c = c +
a
-= Subtract AND It subtracts right operand from the left operand and assign the result c -= a is
to left operand equivalent
to c = c -
a
*= Multiply It multiplies right operand with the left operand and assign the c *= a is
AND result to left operand equivalent
to c = c *
a
/= Divide AND It divides left operand with the right operand and assign the result c /= a is
to left operand equivalent
to c = c /
a
%= Modulus It takes modulus using two operands and assign the result to left c %= a is
AND operand equivalent
to c = c %
a
**= Exponent Performs exponential (power) calculation on operators and assign c **= a is
AND value to the left operand equivalent
to c = c
** a
//= Floor It performs floor division on operators and assign value to the left c //= a is
Division operand equivalent
to c = c //
a
Bitwise operator works on bits and performs bit by bit operation. Assume if a = 60; and
b = 13; Now in the binary format their values will be 0011 1100 and 0000 1101
respectively.
Following table lists out the bitwise operators supported by Python language with an
example each in those, we use the above two variables (a and b) as operands −
a = 0011 1100
b = 0000 1101
~a = 1100 0011
There are following logical operators supported by Python language. Assume variable a holds
10 and variable b holds 20 then
and Logical If both the operands are true then condition becomes true. (a and b)
AND is true.
or Logical OR If any of the two operands are non-zero then condition becomes (a or b)
true. is true.
not Logical NOT Used to reverse the logical state of its operand. Not(a
and b) is
false.
Python’s membership operators test for membership in a sequence, such as strings, lists, or
tuples. There are two membership operators as explained below −
[ Show Example ]
not in Evaluates to true if it does not finds a x not in y, here not in results in a 1 if x is not a
variable in the specified sequence member of sequence y.
and false otherwise.
Identity operators compare the memory locations of two objects. There are two Identity
operators explained below −
The following table lists all operators from highest precedence to lowest.
1
**
2
~+-
3
* / % //
4
+-
5
>> <<
6
&
Bitwise 'AND'
7
^|
8
<= < > >=
Comparison operators
9
<> == !=
Equality operators
10
= %= /= //= -= += *= **=
Assignment operators
11
is is not
Identity operators
12
in not in
Membership operators
13
not or and
Logical operators
The data stored in memory can be of many types. For example, a person's age is stored as
a numeric value and his or her address is stored as alphanumeric characters.
Python has various standard data types that are used to define the operations possible on
them and the storage method for each of them.
Numbers
String
List
Tuple
Dictionary
Number data types store numeric values. Number objects are created when you assign a
value to them. For example −
var1 = 1
var2 = 10
Python's dictionaries are kind of hash table type. They work like associative arrays or
hashes found in Perl and consist of key-value pairs.
A dictionary key can be almost any Python type, but are usually numbers or strings.
Values, on the other hand, can be any arbitrary Python object.
There are several built-in functions to perform conversion from one data type to another.
These functions return a new object representing the converted value.
1 int(x [,base])
Converts x to an integer. base specifies the base if x is a string.
2 long(x [,base] )
Converts x to a long integer. base specifies the base if x is a string.
3 float(x)
Converts x to a floating-point number.
4 complex(real [,imag])
Creates a complex number.
5 str(x)
Converts object x to a string representation.
6 repr(x)
Converts object x to an expression string.
7 eval(str)
Evaluates a string and returns an object.
8 tuple(s)
Converts s to a tuple.
9 list(s)
Converts s to a list.
10 set(s)
Converts s to a set.
11 dict(d)
Creates a dictionary. d must be a sequence of (key,value) tuples.
12 frozenset(s)
Converts s to a frozen set.
13 chr(x)
Converts an integer to a character.
14 unichr(x)
Converts an integer to a Unicode character.
15 ord(x)
Converts a single character to its integer value.
16 hex(x)
Converts an integer to a hexadecimal string.
17 oct(x)
Converts an integer to an octal string.
UNIT I - OVERVIEW
PART-A QUESTIONS
PART-C QUESTIONS