KEMBAR78
Lacture 1- Programming using python.pptx
Programming
using python
BA Sem II
2023-24
Sukhpal
Guest Faculty, DTU
Syllabus
Unit 1:
Introduction to
Python
programming
Unit 2: Inbuilt data
structures (strings,
lists, tuples and
dictionary)
Unit 3: Working
with Python
libraries and writing
functions
Syllabus
 Unit 1: Introduction to Python programming
 Interactive mode and script mode, structure of a program, script execution, debugging-
errors, comments and error messages.
 Identifiers, keywords, constants, variables, data types and assignments.
 Arithmetic operators and expressions, relational operators, conditions and logical operators,
operator precedence.
 Input and output statements, control structures: if-else, loops, break and continue statements.
 Introduction to in-built functions: invoking functions.
 Handling missing data values: isnull, notnull.
Syllabus
 Unit 2: Python data structures (strings, lists, tuples and dictionary)
 Strings: initialize strings, subscript operator, access elements, string operations, built-in
string functions and methods, slicing a string, escape sequences.
 Lists: concepts of mutable lists, list operations: create, initialize, access, traverse,
append/insert new elements, search, sort, replace, removing elements; inbuilt list
functions and methods, list comprehensions.
 Tuples: concepts of immutable tuples, tuple operations: create, initialize, access
elements; tuple assignment, slicing, and indexing.
 Dictionary: concept of key-value pair, literals, operations: create, initialize, access,
traverse, append, add and remove keys, dictionary functions and methods.
Syllabus
 Unit 3: Working with Python libraries and writing functions
 Introduction to python libraries: NumPy, Pandas, Matplotlib, importing libraries.
 Data visualization using Matplotlib library, plotting graphs: line plot, bar chart,
scatter plot.
 NumPy and Pandas datatypes, basic operations: create, access, slice, add and
remove, reshape, indexing.
 Introduction to user-defined functions: parameters, scope of variables, passing
parameters, void functions, functions returning values, invoking functions, lambda
function, passing list, tuple, dictionary as a function parameters.
Reference material (Books)
1. Mckinney, W. (2017). Python for Data Analysis. Second edition,
O’reilly (SPD)
2. VanderPlas, J. (2016). Python Data Science Handbook: Essential Tools
for Working with Data. Second edition, O’reilly (SPD).
3. Guttag, J. V. (2013). Introduction to computation and programming
using Python. MIT Press.
4. Liang, Y. D. (2013). Introduction to Programming using Python.
Pearson.
5. T. Budd, Exploring Python, TMH, 1st Ed, 2011
6. Urban, M. & Murach, J. (2018). Python Programming. Shroff
Reference material (Tutorials)
 Python Tutorial by Python Developers
https://docs.python.org/3/tutorial/index.html
 Python Tutorial by Tutorial Point
https://www.tutorialspoint.com/python/index.htm
 Introduction to Python by W3Schools
https://www.w3schools.com/python/python_intro.asp
 Python Practice Challenge by Hacker-rank
https://www.hackerrank.com/domains/python
Introduction to Programming
 Language
 Programming Language
 Python Programming
 Bits, Bytes, MB, GB, TB, PB, EB, ZB, YB
 Number System-Binary, OD, D, HD
Programming Language (PL)
 To communicate with a person, we need a specific language (to share ideas, opinions with each other), similarly,
to communicate with computers, programmers also need a language is called Programming language.
 It is a set of instructions written in any specific language ( C, C++, Java, Python) to perform a specific task.
Types of programming languages
 Low-Level PLs– machine code in 0s and 1s
 Machine Language – machine code in binary or hexadecimal
 Assembly Language - symbolic and human-understandable form, uses assembler to convert from assembly
language to machine language
 High-Level PLs-requires a compiler or interpreter to translate the program into machine language
 Procedural Oriented PLs – structure program to solve a specific task (e.g. C, Pascal, ALGOL, COBOL,
BASIC)
 Object Oriented PLs - programs are divided into small parts called objects (e.g. C++, Java, Python, C#)
Registers
 Register in computer: Fastest type of memory, located within the CPU, used for storing
temporary data and CPU instructions.
 The size of a register maybe 8, 16, 32, or 64 bits. In 32-bit CPU, each register is 32 bits wide
and it can manipulate 32 bits of data at a time. The modern PCs have 32-bit or 64-bit registers
and are referred to as 32-bit processors and 64-bit processors.
Computer Memory
 Computer Memory is the hardware part of the system which stores data, information, and
instructions.
 Tabular Representation of
Various Memory Sizes
Name Equal To
Bit 1 Bit
Nibble 4 Bits
Byte 8 Bits
Kilobyte 1024 Bytes
Megabyte 1, 024 Kilobytes
Gigabyte 1, 024 Megabytes
Terrabyte 1, 024 Gigabytes
Petabyte 1, 024 Terabytes
Exabyte 1, 024 Petabytes
Zettabyte 1, 024 Exabytes
Yottabyte 1, 024 Zettabytes
Number System
 The number system is a structured way of
representing numbers.
 Different types of number systems
 Decimal (Base 10 – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
 Binary (Base 2 – 0, 1)
 Octal (Base 8 – 0, 1, 2, 3, 4, 5, 6, 7)
 Hexadecimal (Base 16 –
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F; where
A=10, B=11, ..., F=15)
Conversion Between Number Systems
1. Decimal to Binary:
i. Divide the decimal number by 2.
ii. Record the remainder (either 0 or 1).
iii. Repeat until the quotient is 0.
iv. The binary equivalent is the sequence of
remainders read from bottom to top.
2. Binary to Hexadecimal:
i. Group the binary digits into sets of four,
starting from the right.
ii. Convert each group to its hexadecimal
equivalent.
3. Decimal to Hexadecimal:
i. Convert the decimal number to binary.
ii. Convert the binary number to
hexadecimal.
What is Python?
Python is a high-level, interpreted
programming language known for its
simplicity and readability. It's versatile and can
be used for various applications such as web
development, data analysis, machine learning,
scientific computing, and more.
History of Python
Origin: Python was created by Guido van Rossum during 1985-1990
and first released in 1991.
Philosophy: Python's design philosophy emphasizes code readability,
and its syntax allows programmers to express concepts in fewer lines
of code than languages like C++ or Java.
Versions: Over the years, several versions of Python have been
released. The two main versions in use today are Python 2 in 2000 and
Python 3 in 2008, with Python 3 being the most recent and
recommended version. We will be using 3.12.1
Why Learn Python?
Versatility: Python can be used for various purposes, from web
development to data analysis and machine learning.
Readability: Python's syntax is designed to be clear and concise,
making it easier for beginners to understand and write code.
Community Support: Python has a large and active community, which
means plenty of resources, libraries, and frameworks are available.
Career Opportunities: Python skills are in high demand in the tech
industry, offering numerous job opportunities and competitive salaries.
Features of Python
Interpreted Language: Python code is executed line by line, making it
easier to debug and test.
Object-Oriented: Python supports object-oriented programming, allowing
for the creation of reusable and organized code.
Dynamic Typing: Variables in Python are dynamically typed, meaning
you don't need to declare a variable's type explicitly.
Rich Standard Library: Python comes with a comprehensive standard
library that provides modules and functions for various tasks, reducing
the need for external libraries.
Python vs Other Languages
Comparison with C/C++: Python offers higher-level
abstractions and a more concise syntax compared to
languages like C/C++, making it easier to write and
maintain code.
Comparison with Java: While Java is also a versatile
language, Python's simplicity and readability give it an
edge for rapid development and prototyping.
Setting Up Python Environment
Installation
IDEs (Integrated Development
Environments)
Editors
Command Prompt
Installation
Installation
Installation
Installation
Installation
Tick √
Installation
Installation
Installation
Running Python
 Press Window button and search “IDLE”
Python Basic Programs
Python Basic Programs
Python Basic Programs
Python Basic Programs
INTERPRETER Editor
Python Basic Programs
Python Basic Programs
Python Basic Programs
Python at command prompt
 Open command prompt
Python at command prompt
Ctrl + z
IDEs
An integrated development
environment (IDE) is a software
application that helps
programmers develop software
code efficiently.
How to install Spyder and Jupyter Notebook
 Install anaconda for installing these together
How to run Spyder
 Search Spyder in window and run it
INTERACTIVE
INTERPRETER
Editor
How to run Jupyter Notebook
 Search Jupyter Notebook in window and run it
How to run Jupyter Notebook
Python Syntax
INDENTATION COMMENTS
A block of code
must have a
consistent number
of spaces
Variables or Naming
Conventions
 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 case sensitive.
Reserved Keywords
and as assert
break class continue
def del elif
else except False
finally for from
global if import
in is lambda
None nonlocal not
or pass raise
return True try
while with yield
Python Data Types
Operators
• Arithmetic
• Comparison
• Assignment
• Logical
• Bitwise
Basic Data Types
• Integers
• Floats
• Complex
• Booleans
• Strings
Arithmetic
Operators
 + for addition
 - for subtraction
 * for multiplication
 / for division
 // for floor division
 % for remainder
 ** for exponentiation
Comparison
Operators
 == for equality check
 != for not equal
 > for greater than
 < for less than
 >= for greater than or equal to
 <= for less than or equal to
Assignment
Operators
 = for assigning right value into left variable
 A @= B
Let @ be the operation of A and B then A = A @ B and
@ {+, -, *, /, //, %, **, &, ^, |}
Logical
Operators
 Compare True and False Boolean values
 and if both are True will give True otherwise False
 or if both are False will give False otherwise True
 not (unitary operator – used with a single variable) if
given value if False returns True otherwise returns False
Logical
Operators
 Bitwise AND: &
 Bitwise OR: |
 Bitwise XOR (Exclusive OR): ^
 Bitwise NOT (1s complement): ~
 Left Shift: <<
 Right Shift: >>
Data Types
 int
 float
 complex
 bool
 str

Lacture 1- Programming using python.pptx

  • 1.
    Programming using python BA SemII 2023-24 Sukhpal Guest Faculty, DTU
  • 2.
    Syllabus Unit 1: Introduction to Python programming Unit2: Inbuilt data structures (strings, lists, tuples and dictionary) Unit 3: Working with Python libraries and writing functions
  • 3.
    Syllabus  Unit 1:Introduction to Python programming  Interactive mode and script mode, structure of a program, script execution, debugging- errors, comments and error messages.  Identifiers, keywords, constants, variables, data types and assignments.  Arithmetic operators and expressions, relational operators, conditions and logical operators, operator precedence.  Input and output statements, control structures: if-else, loops, break and continue statements.  Introduction to in-built functions: invoking functions.  Handling missing data values: isnull, notnull.
  • 4.
    Syllabus  Unit 2:Python data structures (strings, lists, tuples and dictionary)  Strings: initialize strings, subscript operator, access elements, string operations, built-in string functions and methods, slicing a string, escape sequences.  Lists: concepts of mutable lists, list operations: create, initialize, access, traverse, append/insert new elements, search, sort, replace, removing elements; inbuilt list functions and methods, list comprehensions.  Tuples: concepts of immutable tuples, tuple operations: create, initialize, access elements; tuple assignment, slicing, and indexing.  Dictionary: concept of key-value pair, literals, operations: create, initialize, access, traverse, append, add and remove keys, dictionary functions and methods.
  • 5.
    Syllabus  Unit 3:Working with Python libraries and writing functions  Introduction to python libraries: NumPy, Pandas, Matplotlib, importing libraries.  Data visualization using Matplotlib library, plotting graphs: line plot, bar chart, scatter plot.  NumPy and Pandas datatypes, basic operations: create, access, slice, add and remove, reshape, indexing.  Introduction to user-defined functions: parameters, scope of variables, passing parameters, void functions, functions returning values, invoking functions, lambda function, passing list, tuple, dictionary as a function parameters.
  • 6.
    Reference material (Books) 1.Mckinney, W. (2017). Python for Data Analysis. Second edition, O’reilly (SPD) 2. VanderPlas, J. (2016). Python Data Science Handbook: Essential Tools for Working with Data. Second edition, O’reilly (SPD). 3. Guttag, J. V. (2013). Introduction to computation and programming using Python. MIT Press. 4. Liang, Y. D. (2013). Introduction to Programming using Python. Pearson. 5. T. Budd, Exploring Python, TMH, 1st Ed, 2011 6. Urban, M. & Murach, J. (2018). Python Programming. Shroff
  • 7.
    Reference material (Tutorials) Python Tutorial by Python Developers https://docs.python.org/3/tutorial/index.html  Python Tutorial by Tutorial Point https://www.tutorialspoint.com/python/index.htm  Introduction to Python by W3Schools https://www.w3schools.com/python/python_intro.asp  Python Practice Challenge by Hacker-rank https://www.hackerrank.com/domains/python
  • 8.
    Introduction to Programming Language  Programming Language  Python Programming  Bits, Bytes, MB, GB, TB, PB, EB, ZB, YB  Number System-Binary, OD, D, HD
  • 9.
    Programming Language (PL) To communicate with a person, we need a specific language (to share ideas, opinions with each other), similarly, to communicate with computers, programmers also need a language is called Programming language.  It is a set of instructions written in any specific language ( C, C++, Java, Python) to perform a specific task. Types of programming languages  Low-Level PLs– machine code in 0s and 1s  Machine Language – machine code in binary or hexadecimal  Assembly Language - symbolic and human-understandable form, uses assembler to convert from assembly language to machine language  High-Level PLs-requires a compiler or interpreter to translate the program into machine language  Procedural Oriented PLs – structure program to solve a specific task (e.g. C, Pascal, ALGOL, COBOL, BASIC)  Object Oriented PLs - programs are divided into small parts called objects (e.g. C++, Java, Python, C#)
  • 10.
    Registers  Register incomputer: Fastest type of memory, located within the CPU, used for storing temporary data and CPU instructions.  The size of a register maybe 8, 16, 32, or 64 bits. In 32-bit CPU, each register is 32 bits wide and it can manipulate 32 bits of data at a time. The modern PCs have 32-bit or 64-bit registers and are referred to as 32-bit processors and 64-bit processors.
  • 11.
    Computer Memory  ComputerMemory is the hardware part of the system which stores data, information, and instructions.  Tabular Representation of Various Memory Sizes Name Equal To Bit 1 Bit Nibble 4 Bits Byte 8 Bits Kilobyte 1024 Bytes Megabyte 1, 024 Kilobytes Gigabyte 1, 024 Megabytes Terrabyte 1, 024 Gigabytes Petabyte 1, 024 Terabytes Exabyte 1, 024 Petabytes Zettabyte 1, 024 Exabytes Yottabyte 1, 024 Zettabytes
  • 12.
    Number System  Thenumber system is a structured way of representing numbers.  Different types of number systems  Decimal (Base 10 – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)  Binary (Base 2 – 0, 1)  Octal (Base 8 – 0, 1, 2, 3, 4, 5, 6, 7)  Hexadecimal (Base 16 – 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F; where A=10, B=11, ..., F=15) Conversion Between Number Systems 1. Decimal to Binary: i. Divide the decimal number by 2. ii. Record the remainder (either 0 or 1). iii. Repeat until the quotient is 0. iv. The binary equivalent is the sequence of remainders read from bottom to top. 2. Binary to Hexadecimal: i. Group the binary digits into sets of four, starting from the right. ii. Convert each group to its hexadecimal equivalent. 3. Decimal to Hexadecimal: i. Convert the decimal number to binary. ii. Convert the binary number to hexadecimal.
  • 13.
    What is Python? Pythonis a high-level, interpreted programming language known for its simplicity and readability. It's versatile and can be used for various applications such as web development, data analysis, machine learning, scientific computing, and more.
  • 14.
    History of Python Origin:Python was created by Guido van Rossum during 1985-1990 and first released in 1991. Philosophy: Python's design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than languages like C++ or Java. Versions: Over the years, several versions of Python have been released. The two main versions in use today are Python 2 in 2000 and Python 3 in 2008, with Python 3 being the most recent and recommended version. We will be using 3.12.1
  • 15.
    Why Learn Python? Versatility:Python can be used for various purposes, from web development to data analysis and machine learning. Readability: Python's syntax is designed to be clear and concise, making it easier for beginners to understand and write code. Community Support: Python has a large and active community, which means plenty of resources, libraries, and frameworks are available. Career Opportunities: Python skills are in high demand in the tech industry, offering numerous job opportunities and competitive salaries.
  • 16.
    Features of Python InterpretedLanguage: Python code is executed line by line, making it easier to debug and test. Object-Oriented: Python supports object-oriented programming, allowing for the creation of reusable and organized code. Dynamic Typing: Variables in Python are dynamically typed, meaning you don't need to declare a variable's type explicitly. Rich Standard Library: Python comes with a comprehensive standard library that provides modules and functions for various tasks, reducing the need for external libraries.
  • 17.
    Python vs OtherLanguages Comparison with C/C++: Python offers higher-level abstractions and a more concise syntax compared to languages like C/C++, making it easier to write and maintain code. Comparison with Java: While Java is also a versatile language, Python's simplicity and readability give it an edge for rapid development and prototyping.
  • 18.
    Setting Up PythonEnvironment Installation IDEs (Integrated Development Environments) Editors Command Prompt
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
    Running Python  PressWindow button and search “IDLE”
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
    Python at commandprompt  Open command prompt
  • 36.
    Python at commandprompt Ctrl + z
  • 37.
    IDEs An integrated development environment(IDE) is a software application that helps programmers develop software code efficiently.
  • 38.
    How to installSpyder and Jupyter Notebook  Install anaconda for installing these together
  • 39.
    How to runSpyder  Search Spyder in window and run it INTERACTIVE INTERPRETER Editor
  • 40.
    How to runJupyter Notebook  Search Jupyter Notebook in window and run it
  • 41.
    How to runJupyter Notebook
  • 42.
    Python Syntax INDENTATION COMMENTS Ablock of code must have a consistent number of spaces
  • 43.
    Variables or Naming Conventions 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 case sensitive.
  • 44.
    Reserved Keywords and asassert break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return True try while with yield
  • 45.
    Python Data Types Operators •Arithmetic • Comparison • Assignment • Logical • Bitwise Basic Data Types • Integers • Floats • Complex • Booleans • Strings
  • 46.
    Arithmetic Operators  + foraddition  - for subtraction  * for multiplication  / for division  // for floor division  % for remainder  ** for exponentiation
  • 47.
    Comparison Operators  == forequality check  != for not equal  > for greater than  < for less than  >= for greater than or equal to  <= for less than or equal to
  • 48.
    Assignment Operators  = forassigning right value into left variable  A @= B Let @ be the operation of A and B then A = A @ B and @ {+, -, *, /, //, %, **, &, ^, |}
  • 49.
    Logical Operators  Compare Trueand False Boolean values  and if both are True will give True otherwise False  or if both are False will give False otherwise True  not (unitary operator – used with a single variable) if given value if False returns True otherwise returns False
  • 50.
    Logical Operators  Bitwise AND:&  Bitwise OR: |  Bitwise XOR (Exclusive OR): ^  Bitwise NOT (1s complement): ~  Left Shift: <<  Right Shift: >>
  • 51.
    Data Types  int float  complex  bool  str