0% found this document useful (0 votes)
31 views

Python - Course Manual

The document provides details about a course on basics of Python programming including the course syllabus, delivery plan, outcomes and assessment criteria. The course aims to provide a solid foundation of programming concepts and Python language. Students will learn data structures, functions, file handling and apply their knowledge through exercises.

Uploaded by

Harshit Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Python - Course Manual

The document provides details about a course on basics of Python programming including the course syllabus, delivery plan, outcomes and assessment criteria. The course aims to provide a solid foundation of programming concepts and Python language. Students will learn data structures, functions, file handling and apply their knowledge through exercises.

Uploaded by

Harshit Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Jagannath International Management School

Vasant Kunj, New Delhi-110070


(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Course Manual
Table of Contents
Subject: Basics of Python Programming Semester: 3

S.No. Contents Page No.


e.g.(1.1 – 1.5)
1. Syllabus

2. Course Delivery & Assessment Plan

3. Assignments

4. Mid Term Papers

5. Unit-wise Question Bank

6. End Term Question Papers


(Last Five Years)
7. Additional Reading Material

8. Case Studies (if applicable)


Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Course Delivery & Assessment Plan


Course Title Basics of Python Programming [BCA211]
Core or Elective Elective
Program and Batch BCA (Batch: 2022-25)
Semester & Academic Year 3rd and August 2022 –June 2023
Credits 5
Discipline/Area IT
Provide details, if this course is a Prerequisite Basics of OOPs
for any course/specialization
Name of the Faculty Member/Course Ms. Minal Maheshwari
Instructor
Contact Details of the Faculty Member [email protected]
Phone- 9588812398
Contact Details of Support Staff [email protected]

Consultation Day/s & Time Monday, 2pm-3pm

Introduction to the Course (150-200 Words including justification of the course and in what
ways it’s going to help?):

The Python course offers a comprehensive introduction to programming and the Python language.
Students will gain a solid understanding of core programming concepts such as data structures,
conditionals, loops, variables, and functions. Additionally, the course provides a thorough overview
of the available tools for writing and running Python code, allowing students to quickly dive into
coding.
Through hands-on exercises, students will have the opportunity to apply their knowledge and
practice using commonly used data structures. They will also learn how to write custom functions
and manipulate files through reading and writing operations. This course goes beyond the basics
and explores essential programming topics in greater depth, providing a more robust learning
experience compared to other introductory Python courses.
Python, being a high-level and general-purpose programming language, offers versatility in
application development. Whether it's creating desktop GUI apps, building websites, or developing
online applications, Python proves to be a reliable choice. Its high-level nature allows developers to
focus on the core functionality of their applications, as routine programming tasks are handled
efficiently. Moreover, Python's straightforward grammar rules contribute to maintaining a clear and
manageable code base for the applications developed using the language.
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Program Outcomes (PO):


It is envisioned that the graduates passing out BCA degree, will achieve the following objectives
and will be able to

Programme Objectives (POs) Description


PO1 Understand the fundamental concepts of Computers, Software
hardware and peripheral devices and evolution of computer
technologies.
PO2 Familiarized with Business environment and Information
Technology and its Applications in different domains.
PO3 Gain knowledge to identify, explain and apply functional
programming and object-oriented programming techniques and use
of databases to develop computer programs.
PO4 Analyze, design, implement and evaluate computerized solutions to
real life problems, using appropriate computing methods including
web applications.
PO5 Understand the front end and backend of software applications.
PO6 Gain expertise in at least one emerging technology.
PO7 Acquire knowledge about computer networks, network devices and
their configuration protocols, security concepts at various level etc.
PO8 Apply techniques of software validation and reliability analysis to
the development of computer programs.
PO9 Acquire Technical, Communication and management Skills to
convey or present information, applications, instructions, policies,
procedures, decisions, documentations etc. verbally as well as in
writing.
PO10 Recognize the various issues related to society, environment, health
and vivid cultures and understand the responsibilities to contribute in
providing the solutions.
PO11 Acquire technical skills to lead a productive life in the society as a
professional or as an entrepreneur.

COURSE OUTCOMES (COs):


CO# Detailed Statement of the CO BT Level Mapping to PO #
CO1 Demonstrate knowledge of basic programming BTL2 PO1, PO2, PO3,PO7
constructs in python.
CO2 Illustrates string handling methods and user-defined BTL3 PO1, PO2,
functions in python PO3,PO7, PO10
CO3 Applying data structures primitives like List, BTL2 PO1, PO2, PO3,PO4
Dictionary and tuples.
CO4 Identify the commonly used operations involved in BTL3 PO1, PO2, PO3,
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

file handling PO4,PO7

Course Objectives (COs) Program Outcomes (POs) Assessment Item

On successful completion of This course helps you to develop the This learning outcome
the course, students should following Program Outcomes: will be assessed in the
be able to: following items

CO1: Demonstrate knowledge PO1, PO2, PO3,PO7 A1, A2, A3, A4


of basic programming
constructs in python.
CO2: Illustrates string handling PO1, PO2, PO3,PO7, PO10 A1, A2, A3, A4
methods and user-defined
functions in python
CO3: Applying data structures PO1, PO2, PO3,PO4 A1, A3, A4
primitives like List, Dictionary
and tuples.

CO4: Identify the commonly PO1, PO2, PO3, PO4, A1, A2, A3, A4
used operations involved in file PO7
handling

Evaluation Schema:
The students will be continuously assessed during the course on the following basis:-

Class Participation : 5 Marks


Quiz / Presentation / Assignments : 5 Marks
Class Test-1 : 15 Marks
End Term Examination : 75 Marks
Total Marks : 100 Marks

The course grade will be determined on the basis of


Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Assessment Assessment Weightage Nature Week of POs to be


Item Task Assessment Assessed
A1 Class 5% Individual/ Throughout PO1, PO2,PO3
Participation Group
the semester
(Discussion,
Guest Lectures,
Regularity)
A2 Quiz/ 5% Individual Week 4 PO1, PO2,PO3
Assignment/
Week 10
Presentation
A3 Class Test 10% Individual Week-7 PO1, PO2,PO3

A4 End-term exam 75% Individual After Week- PO1, PO2,PO4,


17 PO5,PO7,PO10

Description of Assessments:
 Class Participation (Discussion, Guest Lectures, Regularity) (5%): The participation of
the students in the class discussion, attending Guest Lectures and regularity in class shall
be evaluated out of 5 marks.
 Quiz/Assignment/Presentation (5%): During the semester, participation in Quiz/
Assignment/Presentation shall be evaluated out of 5 marks.
 Class Test (15%): There will be a class Test of 10% weightage on the completion of Week 6.
 End Term Exam (75%): University conducts end term exam at end of semester of 75%
weightage.

Teaching Pedagogy:
The course is delivered offline; the teaching strategy used would be the use of PPT/slides for
comprehending ideas and a white board for problem-solving. Students would better understand the
steps required and applications of the concepts they had learnt by solving problems. A class
discussion technique will also be used in the course, with intervals for questions and answers. A
structured and detailed guided learning and assessment practice will focus on improving higher-order
thinking and meta-cognition and make good use of questioning and dialogue in doing so.
The teaching pedagogy for this course will mainly include lectures along with PowerPoint
presentations, video lectures, Whiteboard teaching and practicals.

Methodology:
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

 The pedagogy will be lectures, Power Point presentations and exercises.


 Audio visual aids will be used extensively during the course.

Python
Flipped Classroom
Practicals 5%
15%

Presentation
35%
Whiteboard
Teaching
40%

videos
5%

Ethics:
All graded assignments are intended to determine your individual skills, abilities, understanding
and knowledge. If you are having difficulty with your work, it is important to seek help from your
course instructor rather than be tempted to use unfair means to gain marks. Cheating can be of
different forms, although any form of cheating is strictly forbidden. These are, but not limited to:
 Submitting other people's work as your own - either with or without their knowledge.
 Impersonation - taking an assessment on behalf of or pretending to be another student or
allowing another person to take an assessment on your behalf or pretend to be you.
 Plagiarism - taking or using another person's thoughts, writings or inventions as your own.
To avoid plagiarism, you must make sure that quotations, from whatever source, are clearly
identified and attributed at the point where they occur in the text of your work by using one
of the standard conventions for referencing. It is not enough just to list sources in a reference
at the end of your project or dissertation if you do not acknowledge the actual quotations in
the text. Neither is it acceptable to change some of the words or the order of sentences if, by
failing to acknowledge the source properly, you give the impression that it is your own work.
 Duplication - submitting work for assessment that is the same as, or broadly similar to, work
submitted earlier for academic credit, without acknowledgement of the previous submission.
Session Plan
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Unit Topic and Sub Topics Learning Outcome References COs Covered

Week-1
I Basic Introduction: Familiarity with the basic
Origin, Need of Python concepts of programming [T1] [R1]
Programming, Features. to start with the basic
knowledge of how to
I Program structure, store data internally in
identifiers, reserved words, computers’ memory.
CO1, CO2
escape sequences, IDLE-
Python Interpreter
I Python Programming
Introduction: Variables and
assignment statements,
data types
Week-2
I Operators: Assignment, Familiarity with how to
Unary, Binary, Arithmetic, use various types
Relational operators in Python
I Logical, Bitwise Operator
and membership operator [T1] [T2] [R1]
CO1, CO2

I Control Structures: if-


conditional statements, if –
else condition, if-elif-else
condition
Week-3
I Nested if-elif-else Students will learn to use
condition, different conditions and
use of strings.
I Iteration (for Loop and
while loop), Nested Loops, [T1] [T2] [R1] CO1, CO2
break and continue
statement.

I Strings: Slicing,
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Membership
Week-4
I Built in functions (count, Students will learn to
find, capitalize, title) know about the usage of [T1][T2][R1]
functions.
I Lower, upper and swap
case, replace, join CO1, CO2
Programs on Loops
I Isspace (), isdigit(), split(),
startswith(), endswith()).

Week-5
I Revision of control Familiarity with control
structures structures and mutable
and Immutable objects
I Revision of strings along with unit 1 revision. [T1][T2][R1]
CO1, CO2
II Mutable and Immutable
objects

Week-6
II List: creating, initializing, How to create list and its
accessing, slicing, and operations
traversing List [T1][R1][R2]
II List operations: length,
concatenation, repetition,
in, not in, max, min, sum, CO3
all
II List methods: append,
extend, count, remove,
index, pop, insert, sort,
reverse.
Week-8
II Tuples: creating tuples, How to use tuples and
Tuple operations: length, dictionary CO3
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

concatenation, repetition
II Membership, maximum,
minimum, tuple methods: [T1][T2][R1]
count, index.

II Dictionary: creating

Week-9
II Accessing values, adding, How to work with
modifying and deleting dictionary methods and
items in dictionary difference between list
II Dictionary methods: len, and dictionary [T1][T2][R1]
str, clear, CO1, CO3

II Difference between list and


dictionary

Week-10
II Dictionary methods: copy, Usage of various
get, update, copy dictionary methods and
revision of unit 2 [T1][R1]
II Revision of list CO1, CO3

II Revision of Dictionary

Week-11
III Concept of Functions: Understand concept of
Functions: Defining functions.
III Calling and Types of [T1][R1] CO1, CO4
Functions
III Arguments and Return
Values
Week-12

III Formal vs. Actual


Arguments Comparing formal and CO1, CO4
III Scope and Lifetime, actual Arguments and its [T2][R1]
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Keyword Arguments, usage


Default Arguments
III Recursion

Week-13

III Modules: importing How to import module


Modules and create
III Math and Random Module [T2][R2]
CO1, CO2, CO4

III Creating your own


modules
Week-14
III Concept of Packages Understanding concepts
of packages like NumPy
IV NumPy Library:
introduction to NumPy [T1][R2] CO2, CO3, CO4

IV Creation of One-
Dimensional Arrays
Week-15
IV Re-shaping of an Array, Various operations on 1D
Element-wise Operations array [T2][R1]
IV Aggregate Operations, CO5
Array indexing, Array
Slicing
Week-16
IV Insert Row/Columns,
Append Row/Columns, Understanding 2D array
Array Manipulation and their operations.
Operations
IV Multi-Dimensional Arrays, [T2][R2]
CO5
Types of Files (Text file,
Binary Files, CSV file)

IV Creation, writing,
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

appending, Insertion,
deletion, updating,
modification of Data in
into the files.

Support for Differently Abled Persons:

JIMS endeavors to make all its courses accessible to students. The Internal Committee for
Differently Abled Persons has identified conditions that could hinder a student’s overall well-
being. These include physical and mobility related difficulties, visual impairment, hearing
impairment, mental health conditions and intellectual/learning difficulties e.g., dyslexia and
dyscalculia. Students with any known disability needing academic and other support are required to
register with the Internal Committee for Differently Abled Persons.
Students who need support may register any time during the semester up until a month before the
end semester exam begins. Those students who wish to continue receiving support from the
previous semester, must re-register within the first month of a semester. Last minute registrations
and support might not be possible as sufficient time is required to make the arrangements for
support.
The committee maintains strict confidentiality about the identity of the student and the nature of
their disability and the same is requested from faculty members and staff as well. The committee
takes a strong stance against in-class and out-of-class references made about a student’s disability
without their consent and disrespectful comments referring to a student’s disability.
All general queries are to be addressed to [email protected]

ASSIGNMENT – 1
1. Explain escape sequence, reserved keywords and Python interpreter.
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

2. Explain control structure (conditional statements), loops, and break and continue in python.
3. Explain string methods and built-in functions.
4. Explain difference between list, tuple and dictionary. Write program for each.
5. Write a python program to sort array element in the ascending/descending order.

RUBRICS ASSIGNMENT – 1
Q No. 1 Mark 2 Marks 3 Marks 4 Marks 5 Marks
1 Definition Definition of Definition of 3 Detailed Definition +Detailed
of 1 type 2 types types description description+ difference
with between each
Definition

2 Definition Definition of Definition of 3 Definition of Definition of all types+


of 1 type 2 types types 4 types Explanation
3 Definition Definition of Detailed Detailed Detailed Definition +
of 2 3 methods Definition + 1 Definition + 3 Example of each
methods Example Example
4 Definition Definition + Detailed Detailed Detailed Definition +
+2 3 Difference Explanation + Explanation + Example of each
Differences 1 Example 3 Example

5 Definition Definition + Definition + Definition + Definition + program+


program program+ program+ Explanation in detail
Explanation in Explanation
short

ASSIGNMENT – 2
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

1. What is a function in Python? How does it differ from a method? What are the different types
of functions in Python? Briefly describe each type.
2. What is the purpose of the Math module in Python? Give examples of functions available in
this module.
3. Discuss how you can insert, delete, update, or modify data in a text file using Python.
4. Create a binary file with roll number, name and marks. Input a roll number and perform the
following operations:
1. Update the marks.
2. Delete the records.
3. Display the records.
4. Append the records.
5. Search the records.

RUBRICS ASSIGNMENT – 2

Q No. 1 Mark 2 Marks 3 Marks 4 Marks 5 Marks


1 Definition Definition Definition and Definition Detailed explanation of
and one 2 Difference +Difference function+ differ from
Difference +3 types of method+ types of
python function
function

2 Definition Definition Definition +3 Detailed Definition of all types+


+2 function function Definition +2 Explanation +Example
function
3 Definition Definition of Detailed Detailed Detailed Definition +
of 2 3 methods Definition + 1 Definition + 3 Example of each
methods Example Example
4 Creating Creating Creating file+ Creating file+ Detailed Definition +
file file+ 2 3 operation 4 operation Example of each
operation
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Mid Term Papers

Unit-wise Question Bank:


Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

UNIT 1
1. What is the need for Python programming in today's software development industry?
2. Mention some key features of Python programming.
3. Explain the program structure in Python.
4. What are identifiers in Python programming?
5. Provide examples of reserved words in Python.
6. What are escape sequences in Python?
7. Explain the role of IDLE in Python programming. What is an IDLE-Python Interpreter?
8. What are variables and how are they used in Python programming?
9. Explain the concept of assignment statements in Python.
10. Name some commonly used data types in Python.
11. What are assignment operators in Python? Provide examples.
12. Explain the difference between unary and binary operators in Python.
13. Discuss arithmetic operators in Python with examples.
14. How do relational operators work in Python? Provide examples.
15. What are logical operators in Python? How are they used in conditional statements?
16. Explain the concept of bitwise operators in Python.
17. What is the membership operator in Python? Provide an example of its usage.
18. How is the "if" statement used as a conditional statement in Python? Provide an example.
19. What is the purpose of the "if-else" condition in Python? Provide an example.
20. How does the "if-elif-else" condition work in Python? Give an example.
21. What is a nested "if-elif-else" condition? Provide an example.
22. Explain the concept of iteration in Python using the "for" loop. Provide an example.
23. How does the "while" loop work in Python? Give an example.
24. What are nested loops in Python? Provide an example.
25. How do the "break" and "continue" statements work in Python loops? Explain with examples.
26. How can you perform slicing on a string in Python? Provide an example.
27. What is string membership in Python? How is it checked?
28. Explain the usage of the following built-in string functions in Python: count(), find(),
capitalize(), title(), lower(), upper(), swapcase(), replace(), join().
29. How can you check if a string consists of only whitespace characters using a built-in function
in Python?
30. How can you check if a string consists of only digits using a built-in function in Python?
UNIT 2
1. What is the difference between mutable and immutable objects in Python?
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

2. Explain the concept of mutability and immutability with respect to Python objects.
3. Provide examples of mutable objects in Python.
4. Give examples of immutable objects in Python.
5. How can you create a list in Python?
6. Explain the process of initializing a list with values.
7. How do you access individual elements in a list?
8. What is slicing in the context of lists? Provide an example.
9. How can you traverse through a list in Python?
10. Explain the list operations: length, concatenation, repetition, in, not in, max, min, sum, all,
any.
11. What are the common methods available for lists in Python? Explain the purpose of each:
append, extend, count, remove, index, pop, insert, sort, reverse.
12. How can you create a tuple in Python?
13. Explain the concept of tuple operations: length, concatenation, repetition, membership,
maximum, minimum.
14. What are the tuple methods available in Python? Describe the usage of count() and index().
15. How can you create a dictionary in Python?
16. How do you access values in a dictionary?
17. Explain how to add, modify, and delete items in a dictionary.
18. What are the dictionary methods available in Python? Describe the purpose of len(), str(),
clear(), copy(), get(), and update().
19. Compare and contrast lists and dictionaries in Python.
20. What are the key differences between the two data structures in terms of structure and
functionality?
21. In what scenarios would you choose to use a list instead of a dictionary, and vice versa?
UNIT 3
1. What is a function in Python? How does it differ from a method?
2. Explain the process of defining a function in Python.
3. How do you call a function in Python? Provide an example.
4. What are the different types of functions in Python? Briefly describe each type.
5. Discuss the concept of arguments and return values in Python functions.
6. Explain the difference between formal and actual arguments in Python.
7. What is the scope of a variable within a function? How does it differ from the lifetime of a
variable?
8. How are keyword arguments used in Python functions? Provide an example.
9. What are default arguments in Python? How do they work?
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

10. Define recursion and explain how it can be used in Python functions.
11. How do you import modules in Python? Provide examples.
12. What is the purpose of the Math module in Python? Give examples of functions available in
this module.
13. Explain the Random module in Python. Provide examples of functions available in this
module.
14. How can you create your own modules in Python? Provide a step-by-step process.
15. What is a package in Python? Describe the concept of packages and their importance.

UNIT 4
1. What is NumPy? Provide an introduction to the library.
2. How do you create a one-dimensional array using NumPy in Python?
3. Explain the process of reshaping an array in NumPy.
4. What are element-wise operations in NumPy? Give examples.
5. Describe aggregate operations in NumPy. Provide examples.
6. How can you access specific elements in a NumPy array using indexing?
7. What is array slicing in NumPy? Provide an example.
8. Explain how you can insert rows or columns into a NumPy array.
9. How do you append rows or columns to an existing NumPy array?
10. Discuss array manipulation operations available in NumPy.
11. What are multi-dimensional arrays in NumPy? Explain their significance.
12. Name and briefly explain the different types of files used in Python for file handling.
13. How can you create a text file in Python? Provide an example.
14. Explain the process of writing data to a text file in Python.
15. How can you append data to an existing text file in Python?
16. Discuss how you can insert, delete, update, or modify data in a text file using Python.
17. What is a CSV file? How is it different from a text file?
18. Describe the process of reading data from a CSV file in Python.
19. How can you write data to a CSV file in Python? Provide an example.
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

End Term Question Papers:


(Last Five Years)

Additional Reading Material:


Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Unit-1
Strings-
Strings are sequences of characters. Your name can be considered a string. Or, say you live in Delhi,
then your city name is "Delhi", which is a string.
In Python, string is an immutable sequence data type. It is the sequence of Unicode characters
wrapped inside single, double, or triple quotes.
The followings are valid string literals in Python.
'This is a string in Python' # string in single quotes
"This is a string in Python" # string in double quotes
'''This is a string in Python''' # string in triple quotes
"""This is a string in Python""" # string in triple double-quotes

A string literal can be assigned to a variable, as shown below.


str1='This is a string in Python'
print(str1)

str2="This is a string in Python"


print(str2)

Multi-line strings must be embed in triple quotes, as shown below.


str1='''This is
the first
Multi-line string.
'''
print(str1)

str2="""This is
the second
Multi-line
string."""
print(str2)

If a string literal required to embed double quotes as part of a string then, it should be put in single
quotes. Likewise, if a string includes a single quote as a part of a string then, it should be written in
double quotes.
str1='Welcome to "Python Tutorial" on TutorialsTeacher'
print(str1)
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

str2="Welcome to 'Python Tutorial' on TutorialsTeacher"


print(str2)

String Slicing

Slicing is the extraction of a part of a string, list, or tuple. It enables users to access the specific range
of elements by mentioning their indices.
Syntax: Object [start:stop:step]
 “Start” specifies the starting index of a slice
 “Stop” specifies the ending element of a slice
 You can use one of these if you want to skip certain items
You can return a range of characters by using the slice syntax.
Specify the start index and the end index, separated by a colon, to return a part of the string.

Syntax
# slicing from index start to index stop-1
arr[start:stop]
# slicing from index start to the end
arr[start:]
# slicing from the beginning to index stop - 1
arr[:stop]
# slicing from the index start to index stop, by skipping step
arr[start:stop:step]
Example-Get the characters from position 2 to position 5 (not included):
b = "Hello, World!"
print(b[2:5])

Program 1-
# Python program to demonstrate
# string slicing

# String slicing
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

String = 'ASTRING'

# Using slice constructor


s1 = slice(3)
s2 = slice(1, 5, 2)
s3 = slice(-1, -12, -2)

print("String slicing")
print(String[s1])
print(String[s2])
print(String[s3])

Program 2-
# Python program to demonstrate
# string slicing

# String slicing
String = 'Letuslearnpython'

# Using indexing sequence


print(String[:3])

Program 3-
# Python program to demonstrate
# string slicing

# String slicing
String = 'GEEKSFORGEEKS'

# Using indexing sequence


print(String[1:5:2])

String Methods

Method Description
str.capitalize() Returns the copy of the string with its first character capitalized and the rest of the
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Method Description
letters are in lowercased.
string.casefold() Returns a lowered case string. It is similar to the lower() method, but the casefold()
method converts more characters into lower case.
string.center() Returns a new centered string of the specified length, which is padded with the
specified character. The deafult character is space.
string.count() Searches (case-sensitive) the specified substring in the given string and returns an
integer indicating occurrences of the substring.
string.endswith() Returns True if a string ends with the specified suffix (case-sensitive), otherwise
returns False.
string.expandtabs() Returns a string with all tab characters \t replaced with one or more space,
depending on the number of characters before \t and the specified tab size.
string.find() Returns the index of the first occurence of a substring in the given string (case-
sensitive). If the substring is not found it returns -1.
string.index() Returns the index of the first occurence of a substring in the given string.
string.isalnum() Returns True if all characters in the string are alphanumeric (either alphabets or
numbers). If not, it returns False.
string.isalpha() Returns True if all characters in a string are alphabetic (both lowercase and
uppercase) and returns False if at least one character is not an alphabet.
string.isascii() Returns True if the string is empty or all characters in the string are ASCII.
string.isdecimal() Returns True if all characters in a string are decimal characters. If not, it returns
False.
string.isdigit() Returns True if all characters in a string are digits or Unicode char of a digit. If not,
it returns False.
string.isidentifier() Checks whether a string is valid identifier string or not. It returns True if the string
is a valid identifier otherwise returns False.
string.islower() Checks whether all the characters of a given string are lowercased or not. It returns
True if all characters are lowercased and False even if one character is uppercase.
string.isnumeric() Checks whether all the characters of the string are numeric characters or not. It will
return True if all characters are numeric and will return False even if one character
is non-numeric.
string.isprintable() Returns True if all the characters of the given string are Printable. It returns False
even if one character is Non-Printable.
string.isspace() Returns True if all the characters of the given string are whitespaces. It returns
False even if one character is not whitespace.
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Method Description
string.istitle() Checks whether each word's first character is upper case and the rest are in lower
case or not. It returns True if a string is titlecased; otherwise, it returns False. The
symbols and numbers are ignored.
string.isupper() Returns True if all characters are uppercase and False even if one character is not in
uppercase.
string.join() Returns a string, which is the concatenation of the string (on which it is called) with
the string elements of the specified iterable as an argument.
string.ljust() Returns the left justified string with the specified width. If the specified width is
more than the string length, then the string's remaining part is filled with the
specified fillchar.
string.lower() Returns the copy of the original string wherein all the characters are converted to
lowercase.
string.lstrip() Returns a copy of the string by removing leading characters specified as an
argument.
string.maketrans() Returns a mapping table that maps each character in the given string to the
character in the second string at the same position. This mapping table is used with
the translate() method, which will replace characters as per the mapping table.
string.partition() Splits the string at the first occurrence of the specified string separator sep
argument and returns a tuple containing three elements, the part before the
separator, the separator itself, and the part after the separator.
string.replace() Returns a copy of the string where all occurrences of a substring are replaced with
another substring.
string.rfind() Returns the highest index of the specified substring (the last occurrence of the
substring) in the given string.
string.rindex() Returns the index of the last occurence of a substring in the given string.
string.rjust() Returns the right justified string with the specified width. If the specified width is
more than the string length, then the string's remaining part is filled with the
specified fill char.
string.rpartition() Splits the string at the last occurrence of the specified string separator sep argument
and returns a tuple containing three elements, the part before the separator, the
separator itself, and the part after the separator.
string.rsplit() Splits a string from the specified separator and returns a list object with string
elements.
string.rstrip() Returns a copy of the string by removing the trailing characters specified as
argument.
Jagannath International Management School
Vasant Kunj, New Delhi-110070
(Affiliated to Guru Gobind Singh Indraprastha University, New Delhi)
Recognized u/s 2(f) by UGC & Accredited with ‘A’ Grade by NAAC
Participant of UNGC & UNPRME, New York
ISO 9001:2015 Quality Certified

Method Description
string.split() Splits the string from the specified separator and returns a list object with string
elements.
string.splitlines() Splits the string at line boundaries and returns a list of lines in the string.
string.startswith() Returns True if a string starts with the specified prefix. If not, it returns False.
string.strip() Returns a copy of the string by removing both the leading and the trailing
characters.
string.swapcase() Returns a copy of the string with uppercase characters converted to lowercase and
vice versa. Symbols and letters are ignored.
string.title() Returns a string where each word starts with an uppercase character, and the
remaining characters are lowercase.
string.translate() Returns a string where each character is mapped to its corresponding character in
the translation table.
string.upper() Returns a string in the upper case. Symbols and numbers remain unaffected.
string.zfill() Returns a copy of the string with '0' characters padded to the left. It adds zeros (0)
at the beginning of the string until the length of a string equals the specified width
parameter.

You might also like