python programming unit 1 wala ppt .pptx

AnaIyer1 20 views 105 slides Mar 05, 2025
Slide 1
Slide 1 of 105
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105

About This Presentation

python me


Slide Content

PYTHON PROGRAMMING

Course Objective To learn about Python programming language syntax, semantics, and the runtime environment Course Outcomes   After the successful completion of the course, the student will be able to: CO1: To design, implement and test readable, efficient programs that take advantage of Python built-in capabilities and follow Python best practices. CO2: To understand implementation differences and performance tradeoffs associated with various Python data structures. CO3: To manipulate and analyze large datasets and handle missing or inconsistent values. CO4: To identify the right data analytics structure to solve a problem .  

Unit 1: Introduction to Python Introduction to Python-coding styles in python-data types and variables- operators and expressions- numbers and relevant functions-if statement- while statement-for statement-break and continue. arrays - sequences-lists-stack-queues-functional programming- tuples-sequence unpacking- methods- dictionaries–sets- Fundamentals of OOPS in Python-Inheritance, Encapsulation, Polymorphism, Data abstraction. Unit 2: Functions in Python User-defined functions-anonymous functions-recursive functions- introduction to modules-creating and importing and modules-classes and objects-class methods- class properties-static method-constructor- method overriding-inheritance- operator overloading-introduction to pip- installing packages-using python packages. Unit 3: Basics of Numpy NumPy Basics: arrays and vectorized computation-introduction to pandas data structures-series-data frame-index objects-indexing, selection, and filtering- arithmetic and data alignment-applying functions and mapping-sorting and ranking- summarizing and computing descriptive statistics-correlation and covariance-handling missing data- hierarchical indexing. Unit 4: Working with Graphs Data Wrangling-combining and merging data sets- -data transformation-detecting and filtering outliers-string manipulation- vectorized string functions in pandas- plotting and visualization- matplotlib api primer- colors, markers, and line styles- ticks, labels, and legends- annotations and drawing on a subplot- saving plots to file- plotting functions in pandas.

Unit 5: Real time Data Analysis Time Series- date and time data types and tools- converting between string and date time- time series basics- indexing, selection, sub setting- date ranges, frequencies, and shifting-generating date ranges- frequencies and date offsets-time zone handling- quarterly period frequencies- time series plotting-data munging – splicing together data sources- decile and quartile analysis-sample applications-future contract rolling- rolling correlation and linear regression- A Case study on predict the future rating of a restaurant based on an ML model. Reference Books Michael H Goldwasser, David Letscher , “Object Oriented Programming in Python”, Prentice Hall, 1st Edition, 2007. Yashavant Kanetkar , Aditya Kanetkar , “Let us Python, BPB publication, 1st Edition, 2019. Ashok Kamthane , Amit Kamthane , “Programming and Problem solving with Python”, McGraw Hill Education (India) Private Limited, 2018. Taneja Sheetal, Kumar Naveen, “Python Programming – A Modular Approach”, Pearson, 2017. R Nageswara Rao, “Core Python Programming”, Dreamtech Press, 2017 Edition. Peter Wentworth, Jeffrey Elkner , Allen B. Downey and Chris Meyers, “How to Think Like a Computer Scientist: Learning with Python 3”, 3rd Edition, 2015. Paul Barry, “Head First Python a Brain Friendly Guide”, O’Reilly, 2 nd Edition, 2016. Dainel Y.Chen “Pandas for Everyone Python Data Analysis” Pearson Education, 2019.

Question paper Blue print   Unit Hours Allotted in the Syllabus COs Addressed No. of Questions & Marks Distribution Section A Total Marks Section B Total Marks Section C Total Marks I 8 CO1 1 2 1 5 - II 12 CO2 2 4 1 5 1 10 III 14 CO3 2 4 2 10 1 10 IV 12 CO4 1 2 1 5 1 10 V 14 CO4 2 4 2 10 2 20   Bloom’s Taxonomy Level(s) Used Remembering, Understanding Levels Applying, Analyzing Evaluating and Creating Levels Applying, Analyzing, Evaluating and Creating Levels

Python Practical Content Write a python program to open a file and check what are the access permissions acquired by that file using os module. Write a python program to find the linear regression. Write a program to double a given number and add two numbers using lambda(). Write a Python Program to Using a numpy module create an array and check the following: 1. Type of array 2. Shape of array 3. Type of elements in array. Create a dictionary and apply the following methods 1) Print the dictionary items 2) access items 3) use get() 4)change values 5) use len()  Write a python code to read a csv file using pandas module and print the first and last five lines of a file. Write a python code to set background color and pic and draw a circle using turtle module Write a python program to create a package, sub -package, modules and create staff and   student function to module. 9 Write a python program to plot a bar graph for the car data set.  10 Write a python program to create a login web page using pycharm .  

What is Python…? Python is a popular high-level programming language used in various applications Python is an easy language to learn because of its simple syntax Python can be used for simple tasks such as plotting or for more complex tasks like machine learning Python supports modules and packages, which encourages program modularity and code reuse. Python is a general purpose programming language that is often applied in scripting roles. So, Python is programming language as well as scripting language. Python is also called as Interpreted language

The biggest strength of Python is huge collection of standard library which can be used for the following: Machine Learning GUI Applications (like  Kivy , Tkinter , PyQt etc. ) Web frameworks like  Django  (used by YouTube, Instagram, Dropbox) Image processing (like  OpenCV , Pillow) Web scraping (like Scrapy, BeautifulSoup , Selenium) Test frameworks Multimedia Scientific computing Text processing and many more..

What can Python do? Python can be used on a server to create web applications. Python can be used alongside software to create workflows. Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics. Python can be used for rapid prototyping, or for production-ready software development.

History Invented in the Netherlands, early 90s by Guido van Rossum Python was conceived in the late 1980s and its implementation was started in December 1989 Guido V an Ro s s u m i s f an o f ‘Monty P y thon ’ s Fly i ng Circus’, this is a famous TV show in Netherlands Named after Monty Python Open sourced from the beginning

Guido van Rossum “Python is an experiment in how much freedom program-mers need. Too much freedom and nobody can read another's code; too little and expressive-ness is endangered.”

Why was python created? "My original motivation for creating Python was the perceived need for a higher level language in the Amoeba [Operating Systems] project. I realized that the development of system M o r e o v e r , doin g the s e things i n th e Bo urne admi n ist r ation util i t i es i n C w as t a ki n g t o o l o n g . sh e ll wouldn't work for a variety of reasons. ... S o , the r e w as a nee d f or a la n gua g e th a t would bridge the gap between C and the shell” - Guido Van Rossum

Differences between program and scripting language Program a program is executed (i.e. the source is first compiled, and the result of that compilation is expected) A "program" in general, is a sequence of instructions written so that a computer can perform certain task . Scripting a script is interpreted A "script" is code written in a scripting language. A scripting language is nothing but a type of programming language in which we can write code to control another software application.

Differences between program and scripting language Applications of Scripting Languages : 1. To automate certain tasks in a program 2. Extracting information from a data set 3. Less code intensive as compared to traditional programming languages   Applications of Programming Languages : 1. They typically run inside a parent program like scripts 2. More compatible while integrating code with mathematical models 3. Languages like JAVA can be compiled and then used on any platform

Advantages of Python 1. Easy to Read, Learn and Write Python is a  high-level programming language  that has English-like syntax. This makes it easier to read and understand the code. Python is really easy to  pick up  and  learn , that is why a lot of people recommend Python to beginners. You need less lines of code to perform the same task as compared to other major languages like  C/C++  and  Java . 2. Improved Productivity Python is a very  productive language . Due to the simplicity of Python, developers can focus on solving the problem. They don’t need to spend too much time in understanding the  syntax  or  behavior  of the programming language. You write less code and get more things done.

3. Interpreted Language Python is an interpreted language which means that Python directly  executes the code  line by line. In case of any error, it stops further execution and reports back the error which has occurred. Python shows only one error even if the program has multiple errors. This makes  debugging  easier . 4. Dynamically Typed Python doesn’t know the type of variable until we run the code. It automatically assigns the data type during  execution . The programmer doesn’t need to worry about declaring variables and their data types.

5. Free and Open-Source Python comes under the  OSI approved  open-source license. This makes t  free  to  use  and  distribute . You can download the source code, modify it and even distribute your version of Python. This is useful for organizations that want to modify some specific behavior and use their version for development. 6. Vast Libraries Support The standard library of Python is huge, you can find almost all the functions needed for your task. So, you don’t have to depend on external libraries. But even if you do, a  Python package manager (pip)  makes things easier to import other great packages from the  Python package index ( PyPi ) . It consists of over 200,000 packages.

Disadvantages of Python 1. Slow Speed The line by line execution of code often leads to  slow execution . The dynamic nature of Python is also responsible for the  slow speed  of Python because it has to do the extra work while executing code. So, Python is not used for purposes where speed is an important aspect of the project. 2. Not Memory Efficient To provide simplicity to the developer, Python has to do a little tradeoff . The Python programming language uses a  large amount of memory . This can be a disadvantage while building applications when we prefer memory optimization. 3. Weak in Mobile Computing Python is generally used in  server-side programming . We don’t get to see Python on the client-side or mobile applications because of the following reasons. Python is  not memory efficient  and it has  slow processing power  as compared to other languages.

4. Database Access Programming in Python is  easy  and  stress-free . But when we are interacting with the database, it lacks behind. The Python’s database access layer is primitive and underdeveloped in comparison to the popular technologies like  JDBC  and  ODBC . Huge enterprises need smooth  interaction  of complex legacy data and Python is thus rarely used in enterprises. 5. Runtime Errors As we know Python is a dynamically typed language so the data type of a variable can change anytime. A variable containing integer number may hold a string in the future, which can lead to  Runtime Errors . Therefore Python programmers need to perform thorough testing of the applications.

Why do people use Python…? The following primary factors cited by Python users seem to be these: Python is object-oriented Structure supports such concepts as polymorphism, operation overloading, and multiple inheritance. Indentation Indentation is one of the greatest future in Python. It's free (open source) Downloading and installing Python is free and easy Source code is easily accessible

It's powerful Dynamic typing Built-in types and tools Library utilities Third party utilities (e.g. Numeric, NumPy, SciPy) Automatic memory management It's portable Python runs virtually every major platform used today As long as you have a compatible Python interpreter installed, Python programs will run in exactly the same manner, irrespective of platform.

It's mixable Python can be linked to components written in other languages easily L i n ki n g t o fas t , c o m pi l ed c o de i s us ef ul t o co m p u t a t i onally i nt e n s ive problems - Python/C integration is quite common It's easy to use No intermediate compile and link steps as in C/ C++ P y thon progr a m s a r e co m pi l ed aut o m a ti c ally to a n inte r m ed i ate form called bytecode , which the interpreter then reads This gives Python the development speed of an interpreter without the performance loss inherent in purely interpreted languages It's easy to learn Structure and syntax are pretty intuitive and easy to grasp

Where is python used in the Industry

Where is python used in the Industry

Coding Styles in python There are four different coding styles offered by python. They are Functional Imperative Object-oriented Procedural Functional coding In the functional type of coding, every statement is treated as a Mathematical equation and mutuable . Most of the programmers prefer this type of coding for recursion and lambda calculus.  Python Code: my_list = [1, 5, 4, 6, 8, 11, 3, 12] new_list = list(map(lambda x: x * 2 , my_list )) print( new_list ) Output: [2, 10, 8, 12, 16, 22, 6, 24]

Imperative coding When there is a change in the program, computation occurs. Imperative style of coding is adopted, if we have to manipulate the data structures. Python Code: sum = 0 for x in my_list : sum += x print(sum) Output: 50

Object-oriented coding This type of coding relies on the data fields, which are treated as objects. These can be manipulated only through prescribed methods. Python doesn’t support this paradigm completely, due to some features like encapsulation cannot be implemented. Python Code: class word: def test(self): print("Python") string = word() string.test () Output: Python

Procedural coding It is used for iteration, sequencing, selection, and modularization. Python Code: def add(list): sum = 0 for x in list: sum += x return sum print(add( my_list ))

Comments in Python

Keywords in Python

Difference between Interactive and Script mode in Python Interactive mode: Instructions are given in front of Python prompt ( eg. , >>> ) in Python Shell. Python carries out the given instruction and shows the result there itself. Script mode: Python instructions are stored in a file generally with . py extension and are executed together in one go as a unit. The saved instructions are known as Python script or Python program .

Working with Python Default installation from www.python.org is called Cpython installation and comes with Python interpreter, Python IDLE(Python GUI) and Pip(package installer). Other Python distributions – Anaconda Python distribution that comes preloaded with many packages and libraries( eg . Numpy,SciPy,Panda libraries,etc .) Popular IDEs – Spyder IDE,PyCharm IDE etc. Spyder IDE is already available as a part of Anaconda Python Distribution.

Major Packages,libraries,frameworks Numpy ( NUMeric Python) : matrices and linear algebra Scipy ( SCIentific Python) : many numerical routines Pandas : data analysis and modeling library Pytest (Python TESTing ) : a code testing framework

How to install Python on Windows There are two main ways of installing Python on Windows: installation from the official  Python website   Anaconda , a convenient distribution of Python. Choose the first option if you are a programmer using Python for various purposes: creating websites, network programming, developing software applications. If instead, your work is focused on data science and  machine learning , then Anaconda is the best choice for you.

Check if Python is already installed Before starting the installation process, we want to check if Python is already installed on your computer (e.g., by a previous user), and if so, which version of Python.  open the command line application Command Prompt - and type there python -V If you found that Python is already installed on your computer and want to check the path of the installation, run where.exe python in the command line application.

Install Python on Windows from the official Python website Step 1. Open the  Python Releases for Windows  page, select Python version, and download Python executable installer.

Step 2: Run the Python Installer for how to install python on windows downloads folder  Make sure to mark  Add Python 3.10 to PATH  otherwise you will have to do it explicitly. It will start installing python on windows. 

Step 3: Go to windows and type IDLE This is Python Interpreter also called Python Shell. I printed Hello Jasmine, python is working smoothly. The three greater than >>> sign is called Python command prompt, where we write our program and with a single enter key, it will give result so instantly.

Installing Anaconda on Windows

Variable and data type in Python

Variables Variables are containers for storing data values. Creating Variables Python has no command for declaring a variable. A variable is created the moment you first assign a value to it. x =  5 y =  "John" print (x) print (y)

Variable Names A variable can have a short name (like x and y) or a more descriptive name (age, carname , total_volume ). Rules for Python variables: A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables) A variable name cannot be any of the Python keywords.

Multi Words Variable Names Variable names with more than one word can be difficult to read. There are several techniques you can use to make them more readable: Camel Case Each word, except the first, starts with a capital letter: myVariableName = "John"

Pascal Case Each word starts with a capital letter: MyVariableName = "John“ Snake Case Each word is separated by an underscore character: my_variable_name =  "John"

Many Values to Multiple Variables Python allows you to assign values to multiple variables in one line: x, y, z =  "Orange" ,  "Banana" ,  "Cherry" print (x) print (y) print (z) One Value to Multiple Variables And you can assign the  same  value to multiple variables in one line: x = y = z =  "Orange" print (x) print (y) print (z)

Variable and data type in Python

List Lists are used to store multiple items in a single variable. A Python list contains items separated by commas and enclosed within square brackets ([]).  Python lists are similar to arrays in C. One difference between them is that all the items belonging to a Python list can be of different data type where as C array can store elements related to a particular data type. The values stored in a Python 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.

Tuple Data Type Python tuple is another sequence data type that is similar to a list. A Python tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses. The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Tuples can be thought of as  read-only  lists.

Range()

Dictionary In Python, you can use the built-in dict data type to create and manipulate dictionaries. Dictionaries are a type of collection that store key-value pairs, where each key maps to a value. Dictionaries are also known as associative arrays or hashmaps in other programming languages. Creating a dictionary: You can create a dictionary using curly braces {} and separating key-value pairs with colons :.

# Empty dictionary empty_dict = {} # Dictionary with initial key-value pairs my_dict = { "name": "John", "age": 30, "city": "New York" }

# Adding new key-value pair my_dict ["occupation"] = "Engineer" # Modifying an existing value my_dict ["age"] = 31 print( my_dict ) # Output: {'name': 'John', 'age': 31, 'city': 'New York', 'occupation': 'Engineer'}

SET In Python, a set is an unordered collection of unique elements. It is a built-in data type that allows you to store and perform set operations like union, intersection, difference, and more. Sets are denoted using curly braces {} or by using the set() constructor. Here's a basic introduction to working with sets in Python: Creating a set: You can create a set by enclosing elements inside curly braces {}.

Example set1 = set() set2 = {'James', 2, 3,'Python'} #Printing Set value print(set2) # Adding element to the set set2.add(10) print(set2) #Removing element from the set set2.remove(2) print(set2)

Python divides the operators in the following groups: Arithmetic operators Assignment operators Comparison operators Logical operators Identity operators Membership operators Bitwise operators

For Loop It has the ability to iterate over the items of any sequence, such as a list or a string. Syntax for iterating_var in sequence: statements(s) If a sequence contains an expression list, it is evaluated first. Then, the first item in the sequence is assigned to the iterating variable iterating_var . Next, the statements block is executed. Each item in the list is assigned to iterating_var , and the statement(s) block is executed until the entire sequence is exhausted.
Tags