0% found this document useful (0 votes)
284 views3 pages

Python Data Types and Applications

Uploaded by

viksonio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
284 views3 pages

Python Data Types and Applications

Uploaded by

viksonio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

L T P C

0 1 2 2
II Year I Semester
PYTHON PROGRAMMING
(Skill Enhancement Course)

Course Objectives:

The main objectives of the course are to

a. Introduce core programming concepts of Python programming language.


b. Demonstrate about Python data structures like Lists, Tuples, Sets and dictionaries
c. Implement Functions, Modules and Regular Expressions in Python Programming
and to create practical and contemporary applications using these

Course Outcomes:
Upon successful completion of the course, the student will be able to:
 Apply Python's fundamental components, construct control flow statements, perform
input/output operations, manage exceptions, and develop well-structured, efficient, and
robust Python programs.
 Apply functions and their arguments, manage variable scope and lifetime, handle
command line arguments, manipulate strings and lists using various operations and
methods, and utilize built-in functions and commonly used modules to develop efficient
Python programs.
 Apply built-in functions and methods on dictionaries, tuples, and sets, utilize tuples and
sets for efficient data handling.
 Utilize file methods and modules to perform file operations, define and apply object-
oriented programming principles by developing classes and objects, and implement
encapsulation, inheritance, and polymorphism to construct robust and maintainable
Python programs.
 Apply functional programming principles, work with JSON and XML data formats,
utilize NumPy for numerical computations, and manipulate data efficiently using Pandas
to perform data science tasks and analyses effectively.

UNTI-I: History of Python Programming Language, Thrust Areas of Python, Installing


Anaconda Python Distribution, Installing and Using Jupyter Notebook.
Parts of Python Programming Language: Identifiers, Keywords, Statements and
Expressions, Variables, Operators, Precedence and Associativity, Data Types, Indentation,
Comments, Reading Input, Print Output, Type Conversions, the type () Function and Is
Operator, Dynamic and Strongly Typed Language.
Control Flow Statements: if statement, if-else statement, if...elif…else, Nested if statement,
while Loop, for Loop, continue and break Statements, Catching Exceptions Using try and
except Statement.

Sample Experiments:
1. Write a program to find the largest element among three Numbers.
2. Write a Program to display all prime numbers within an interval
3. Write a program to swap two numbers without using a temporary variable.
4. Demonstrate the following Operators in Python with suitable examples.
i) Arithmetic Operators ii) Relational Operators iii) Assignment Operatorsiv) Logical
Operators v) Bit wise Operators vi) Ternary Operator vii) Membership Operators
viii) Identity Operators
5. Write a program to add and multiply complex numbers
6. Write a program to print multiplication table of a given number.

UNIT-II: Functions: Built-In Functions, Commonly Used Modules, Function Definition and
Calling the function, return Statement and void Function, Scope and Lifetime of Variables,
Default Parameters, Keyword Arguments, *args and **kwargs, Command Line Arguments.
Strings: Creating and Storing Strings, Basic String Operations, Accessing Characters in
String by Index Number, String Slicing and Joining, String Methods, Formatting Strings.
Lists: Creating Lists, Basic List Operations, Indexing and Slicing in Lists, Built-In Functions
Used on Lists, List Methods, del Statement.

Sample Experiments:
1. Write a program to define a function with multiple return values.
2. Write a program to define a function using default arguments.
3. Write a program to find the length of the string without using any library functions.
4. Write a program to check if the substring is present in a given string or not.
5. Write a program to perform the given operations on a list:
i. Addition ii. Insertion iii. slicing
6. Write a program to perform any 5 built-in functions by taking any list.

UNIT-III: Dictionaries: Creating Dictionary, Accessing and Modifying key:value Pairs in


Dictionaries, Built-In Functions Used on Dictionaries, Dictionary Methods, del Statement.
Tuples and Sets: Creating Tuples, Basic Tuple Operations, tuple() Function, Indexing and
Slicing in Tuples, Built-In Functions Used on Tuples, Relation between Tuples and Lists,
Relation between Tuples and Dictionaries, Using zip() Function, Sets, Set Methods,
Frozenset.

Sample Experiments:
1. Write a program to create tuples (name, age, address, college) for at least two
members and concatenate the tuples and print the concatenated tuples.
2. Write a program to count the number of vowels in a string (No control flow allowed).
3. Write a program to check if a given key exists in a dictionary or not.
4. Write a program to add a new key-value pair to an existing dictionary.
5. Write a program to sum all the items in a given dictionary.

UNIT-IV: Files: Types of Files, Creating and Reading Text Data, File Methods to Read and
Write Data, Reading and Writing Binary Files, Pickle Module, Reading and Writing CSV
Files, Python os and [Link] Modules.
Object-Oriented Programming: Classes and Objects, Creating Classes in Python, Creating
Objects in Python, Constructor Method, Classes with Multiple Objects, Class Attributes Vs
Data Attributes, Encapsulation, Inheritance, Polymorphism.
Sample Experiments:
1. Write a program to sort words in a file and put them in another file. The output file
should have only lower-case words, so any upper-case words from source must be
lowered.
2. Python program to print each line of a file in reverse order.
3. Python program to compute the number of characters, words and lines in a file.
4. Write a program to create, display, append, insert and reverse the order of the items
in the array.
5. Write a program to add, transpose and multiply two matrices.

6. Write a Python program to create a class that represents a shape. Include methods to
calculate its area and perimeter. Implement subclasses for different shapes like circle,
triangle, and square.

UNIT-V: Introduction to Data Science: Functional Programming, JSON and XML in


Python, NumPy with Python, Pandas.

Sample Experiments:
1. Python program to check whether a JSON string contains complex object or not.
2. Python Program to demonstrate NumPy arrays creation using array () function.
3. Python program to demonstrate use of ndim, shape, size, dtype.
4. Python program to demonstrate basic slicing, integer and Boolean indexing.
5. Python program to find min, max, sum, cumulative sum of array
6. Create a dictionary with at least five keys and each key represent value as a list where
this list contains at least ten values and convert this dictionary as a pandas data frame
and explore the data through the data frame as follows:
a) Apply head () function to the pandas data frame
b) Perform various data selection operations on Data Frame
7. Select any two columns from the above data frame, and observe the change in one
attribute with respect to other attribute with scatter and plot operations in matplotlib
Reference Books:
1. Gowrishankar S, Veena A., Introduction to Python Programming, CRC Press.
2. Python Programming, S Sridhar, J Indumathi, V M Hariharan, 2ndEdition, Pearson,
2024
3. Introduction to Programming Using Python, Y. Daniel Liang, Pearson.
Online Learning Resources/Virtual Labs:
1. [Link]
[Link]

Common questions

Powered by AI

Python lists allow ordered collections and are mutable, providing flexibility in data manipulation . Tuples are immutable and their usage generally enhances execution speed and integrity of the data . Sets support unordered collections with no duplicates, offering efficient checks for membership operations . Dictionaries, with key-value pairs, allow fast retrieval of data values based on associative keys, which is efficient for data lookup tasks .

The main differences between tuples and lists are mutability and performance. Lists are mutable, allowing for manipulation such as addition, removal, or modification of elements, whereas tuples are immutable, providing data integrity once created . This immutability in tuples leads to faster performance in scenarios where data does not need modification . These properties dictate their use cases: lists offer flexibility, while tuples provide reliability and efficiency for fixed data.

Using Python's built-in functions and methods allows for operations like filtering, mapping, and reduction with minimal coding effort, increasing code readability and efficiency . These functions, being implemented in C, are highly optimized, which can lead to significant performance improvements when handling large datasets .

NumPy provides multi-dimensional array objects and an assortment of routines for fast operations on arrays, including mathematical, logical, shape manipulation, and sorting operations . Pandas elevate these capabilities by offering data structures like Series and DataFrames for handling larger datasets, alongside functions for data alignment, indexing, and handling missing data . Together, they deliver a powerful combination for conducting complex data analyses efficiently.

Using command line arguments enables Python programs to be executed with varying inputs and configurations without modifying the source code, enhancing program flexibility and reusability . This allows users to interact with programs dynamically by passing different parameter values directly via the command interface .

Python offers libraries like 'json' to quickly and easily parse and manipulate JSON data, supporting efficient data exchange in web applications . For XML, libraries such as 'xml.etree.ElementTree' provide capabilities to parse and navigate XML documents, making data processing tasks in data science applications less cumbersome . These capabilities allow Python to handle structured data formats fluidly, a common requirement in data science tasks.

Control flow statements like if-else, loops (for, while), and control keywords (break, continue) allow programmers to execute code conditions, repeat code execution, and handle exceptions effectively, thus forming the backbone of decision-making and iterative tasks in software logic . Using these constructs ensures that programs perform as expected under various conditions, leading to efficient and adaptable code.

Python's exception handling mechanism, using try-except blocks, allows programs to gracefully manage errors and exceptions without crashing, providing alternative execution paths or messages for error recovery . This capability enhances program reliability and user experience by handling unexpected inputs or situations smoothly.

Python's dynamic typing allows for flexibility by allowing variable types to change, which speeds up the development process . Its strong typing prevents accidental data loss or corruption by enforcing that operations on incompatible types are disallowed, thus maintaining data integrity during execution . These characteristics emblematic of robustness make Python suitable for diverse and dynamically changing environments.

Encapsulation in Python allows for bundling of data and methods, limiting access to certain components to prevent accidental interference and misuse . Inheritance enables new classes to inherit from existing ones, thus promoting code reuse and reducing redundancy . Polymorphism allows objects to be treated as instances of their parent class, providing flexibility in code by enabling one interface to address different underlying forms of data or types . Combined, these principles facilitate robust, maintainable, and scalable software solutions.

You might also like