Programming Notes (Pythun) Chapter Wise
Programming Notes (Pythun) Chapter Wise
Introduction:
Python is a high-level programming language that is widely used for web development,
scientific computing, data analysis, artificial intelligence, and more. It has a simple and
easy-to-learn syntax, making it a great choice for beginners. Python also has a large
and supportive community, which means that there are many resources and libraries
available to help you learn and use the language. Some popular libraries include
NumPy, pandas, and Matplotlib for data analysis, and TensorFlow and PyTorch for
machine learning.
Python is a versatile programming language and can be used for a wide range of tasks,
some of the most popular being:
1. Web Development: Python frameworks like Django and Flask can be used to
build web applications easily.
2. Data Science: Python has a number of libraries and frameworks such as NumPy,
pandas, Matplotlib, and Seaborn that make it a go-to language for data analysis
and visualization.
3. Machine Learning and Artificial Intelligence: Python has popular libraries such as
TensorFlow, PyTorch, Scikit-learn and Keras which makes it easy to build
models for ML and AI.
4. Scientific Computing: Python is widely used in scientific computing tasks such as
simulations and data analysis in fields like physics, chemistry, and biology.
5. Automation and Scripting: Python can be used to automate repetitive tasks, and
it's also used to write scripts for various purposes like system administration, web
scraping, and more.
6. Game Development: Python has libraries like Pygame that can be used for game
development.
7. Internet of Things (IoT): Python is commonly used for IoT projects due to its
ability to interact with hardware and its large ecosystem of libraries.
8. Business Applications: Due to its simplicity, readability and expressiveness,
Python is used in many business applications and in a variety of roles such as
finance, e-commerce, and more.
LAB 1
Introduction of different working environment in python:
There are several different environments in which you can work with Python, including:
IDLE:
IDLE is a basic integrated development environment (IDE) that comes with Python. It
provides a simple text editor for writing code and a shell for running it.
Jupyter Notebook:
Jupyter Notebook is a web-based IDE that is widely used for data science and scientific
computing. It allows you to write and run code, as well as include text, images, and
other media in the same document.
PyCharm:
PyCharm is a full-featured IDE that is popular among Python developers. It includes
features such as code completion, debugging, and version control.
Practice Exercises
LAB-2
Make program by using different variable, data types and arithmetic
operators and comparison operators.
Variables:
In Python, variables are used to store values that can be used later in the program.
They are declared using a variable name, followed by the assignment operator (=) and
the value being assigned to the variable.
Data Types:
In Python, there are several different data types that can be used to store different types
of information. Some of the most commonly used data types include:
Integer: This data type is used to store whole numbers, such as 1, 2, 3, etc. They are
declared using the keyword "int".
Float: This data type is used to store decimal numbers, such as 1.2, 3.14, etc. They
are declared using the keyword "float".
String: This data type is used to store text or characters, such as "hello" or "world".
They are declared using the keyword "str" or by using double or single quotes.
Boolean: This data type is used to store true or false values, such as True or False.
They are declared using the keyword "bool".
Arithmetic operators
In Python, there are several arithmetic operators that can be used to perform
mathematical operations on numbers. These operators include:
(addition): This operator is used to add two numbers together. For example: 2 + 3 =
5.
(subtraction): This operator is used to subtract one number from another. For
example: 5 - 2 = 3.
/ (division): This operator is used to divide one number by another. For example: 6 /
2 = 3.
% (modulus): This operator is used to find the remainder when one number is
divided by another. For example: 7 % 3 = 1.
// (floor division): This operator is used to divide one number by another and round
down to the nearest whole number. For example: 7 // 3 = 2.
Comparison Operators.
These operators include:
== (equal to): This operator is used to check if two values are equal. For example: 3
== 3 returns True, while 3 == 4 returns False.
!= (not equal to): This operator is used to check if two values are not equal. For
example: 3 != 4 returns True, while 3 != 3 returns False.
(greater than): This operator is used to check if one value is greater than another.
For example: 3 > 2 returns True, while 3 > 3 returns False.
< (less than): This operator is used to check if one value is less than another. For
example: 3 < 4 returns True, while 3 < 3 returns False.
= (greater than or equal to): This operator is used to check if one value is greater
than or equal to another. For example: 3 >= 3 returns True, while 3 >= 4 returns False.
<= (less than or equal to): This operator is used to check if one value is less than
or equal to another. For example: 3 <= 3 returns True, while 3 <= 2 returns False.
Practice Exercises
Final Lab
LAB-3
Make program for different type of strings and their functions.
Strings:
In Python, strings are used to store text or character data. They are declared using
single or double quotes, like this:
Once a string is declared, its value can be accessed and used throughout the program.
Practice Exercises
Final Lab
Lab-4
Make programs by using different conditional expressions.
In Python, conditional expressions are used to make decisions in a program based on
the values of certain variables or expressions. These decisions are made using the
keywords "if", "elif" (short for "else if"), and "else".
if condition:
else:
Practice Exercises
Final Lab
LAB-5
For loop: This type of loop is used to iterate over a sequence of items, such as a list,
string, or range of numbers.
While loop: This type of loop is used to repeat a certain block of code as long as a
certain condition is True.
Practice Exercises
FINAL LAB
LAB-6
Make programs by using different type of functions
In Python, a function is a block of code that can be reused multiple times. Functions are
defined using the "def" keyword, followed by the name of the function, a set of
parentheses, and a colon. The code within the function is indented under the definition.
Functions can take input in the form of parameters, and can return output using the
"return" keyword.
Practice Exercises
FINAL LAB
LAB-7
Make programs by using lists and tuples
List:
A list is a collection of items that are ordered and changeable. Lists are written with square
brackets [] and the items inside the list are separated by commas. They are used to store
multiple items in a single variable.
Tuples:
A tuple is a collection of ordered and immutable items. Tuples are similar to lists, but they are
defined using parentheses () rather than square brackets []. Once a tuple is created, its values
cannot be modified.
Practice Exercises
FINAL LAB
LAB-8
Make programs by using dictionary and sets.
Dictionary:
A dictionary is a collection of key-value pairs, where each key is unique. Dictionaries are
also known as associative arrays or hash maps. They are defined using curly braces {}
and are separated by a comma. The key and value are separated by a colon.
Sets:
In Python, a set is a collection of unique items. Sets are defined using curly braces {}
(just like dictionaries) but they have no key-value pairs, only values. Sets are unordered
and do not support indexing, so you cannot access items in a set by specifying their
index number.
Practice Exercises
Final Lab
LAB-9
Make program using Arrays:
Arrays:
An array is a data structure that stores a collection of items of the same type, such as
numbers or characters. The array module provides a way to create and manipulate
arrays of numerical data. The array objects are more efficient than lists, as they are
implemented in C and allow for more efficient use of memory and computation.
Practice Exercises
Lab-10
Make program using Numpy:
Numpy:
NumPy is a Python library that stands for 'Numerical Python'. It is a powerful library for
the Python programming language, used for working with arrays of multidimensional
data. It provides a high-performance multidimensional array object, and tools for
working with these arrays.
Practice Exercise
Final Lab
LAB-11
Introduction to graphing using Matplotlib
Matplotlib:
Matplotlib is a plotting library for the Python programming language. It provides an
object-oriented API for embedding plots into applications using general-purpose GUI
toolkits like Tkinter, wxPython, Qt, or GTK. Matplotlib provides a wide variety of plots
and charts, including line plots, scatter plots, bar plots, histograms, and more.
Practice Exercises
Final Lab
Lab-12
Introduction to basic datascience using pandas
What is python pandas?
Pandas is a library for the Python programming language for data manipulation and
analysis. It provides data structures and data manipulation functions to handle and
analyze structured data, such as data in tables or dataframes. It is widely used in data
science and scientific computing.
Series:
A Series is a one-dimensional labeled array that can hold any data type. It is similar to a
column in a spreadsheet or a dataset in R. Each element in a Series has a unique label,
called the index, which can be used to access and manipulate the data. A Series can be
created from a list, numpy array, or dictionary. It has methods for performing
mathematical operations, handling missing data, and more. You can also perform
operations on multiple series such as adding,substracting and many more in pandas.
Data Frame:
A DataFrame is a two-dimensional, size-mutable, and heterogeneous tabular data
structure with labeled axes (rows and columns). It is similar to a spreadsheet or a SQL
table, and is commonly used in data analysis and manipulation tasks using Python
libraries such as Pandas. DataFrames can be created from various sources including
lists, dicts, and CSV files, and can be manipulated using a variety of methods, including
filtering, sorting, and grouping.
Practice Exercises
Final Lab