Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Python for Problem Solving

Uploaded by

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

Python for Problem Solving

Uploaded by

spandanabv72
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Python for Problem Solving

Python Programming Syllabus

1. Getting Started with Python Programming

• Introduction to Python
o What is Python?
o History of Python
o Key Features of Python
▪ Python is Easy to Learn and Use
▪ High Level Language
▪ Python is Interpreted
▪ Dynamic Typed
▪ Object Oriented
▪ Extensive Library are Available
▪ Open-Source with Huge community Support
▪ Cross Platform
▪ Good Career Opportunities
o What can you do with Python?
o Why Learn Python?
o Limitation of Python
▪ Performance Limitations
▪ Not preferred for Mobile Apps and Front End
▪ Memory Expensive
▪ Lack of Strong Typing
▪ Not Suitable for Game development
o Python Versions
• Syntax
o Indentation in Python
o Python Variables
o Python Identifiers
▪ Rules
o Python keywords
o Comments in Python
o Multiple Line Statements
o Continuation of Statements in Python
o Taking Input from User in Python
• Comments
o Single-Line Comments
o Multi-Line Comments
▪ Using String Literals as Comment
o Best Practice to Write Comments
• Variables
o Declaration and Initialization of Variables
o Redeclaring variables in Python
o Python Assign Values to Multiple Variables
o Assigning different values to multiple variables
o Can We Use the Same Name for Different Types?
o How does + operator work with variables?
o Can we use + for different Datatypes also?
o Global and Local Python Variables
o Global keyword in Python
▪ Rules of global keyword
o Variable Types in Python
o Object Reference in Python
• Keywords
o List of Keywords in Python
o Getting List of all Python keywords
o Value Keywords: True, False, None Keyword, del
o Operator Keywords: and, or, not, in, is
o Conditional keywords in Python: if, else, elif
o Iteration Keywords: for, while, break, continue, pass in Python
o Exception Handling Keywords
o del Keyword in Python
o Structure Keywords: def, class, return, lambda
o Return Keywords – Return, Yield
o Lambda Keyword in Python
o Context Keywords: With, as Keyword in Python
o as Keyword In Python
o Import and Module: Import, From in Python
o Global and nonlocal keyword uses in Python
o Async Programming: async, await
• Indentation and why is it important
o Why it is and with errors
2. Input/OutputPrint output using print() function

• Python – Print Output using print() function


▪ print() Function Syntax
▪ How print() works in Python?
o Python String Literals
▪ Print Concatenated Strings with +
▪ “end” parameter in print()
▪ “sep” parameter in print()
▪ print() Function with file parameter
o How to Format Output with print() in Python?
▪ Using the format() method
▪ Using f-strings (Python 3.6+)
▪ Using the % operator
• Print without a new line
o Python end parameter in print()
▪ Using sep and end parameter together
• sep parameter in print()
o Python | sep parameter in print()
• Output Formatting
o Output Formatting in Python
▪ Formatting Output using String Modulo Operator(%)
▪ Formatting Output using The Format Method
▪ Formatting Output using The String Method
o Python’s Format Conversion Rule
• Taking Input in Python
o input ( prompt )
▪ How the input function works in Python
o raw_input ( prompt )
• Taking Multiple Inputs from Users
o Using input() and split()
o Using List Comprehension (Multiple Inputs in One Line)
o Using map() for Multiple Integer Inputs
o Taking Multiple Inputs in a Loop

3. Python Data Types

• Data Types
o Strings
▪ Creating a String
• Multi-line Strings
• Accessing characters in Python String
o Access string with Negative Indexing
o String Slicing
▪ String Immutability
▪ Deleting a String
▪ Updating a String
▪ Common String Methods
• len()
• upper() and lower()
• strip() and replace()
▪ Concatenating and Repeating Strings
▪ Formatting Strings
• Using f-strings
• Using format()
▪ Using in for String Membership Testing
o Numbers
▪ Python Integer
▪ Python Float
▪ Python Complex
▪ Type Conversion in Python
▪ Random Numbers
▪ Special Numbers in Python
• NaN (Not a Number)
• Infinity and -Infinity
o Boolean
▪ Python Boolean Type
▪ Evaluate Variables and Expressions
• Python bool() Function
• Integers and Floats as Boolean
▪ Boolean Operators
• Boolean OR Operator
• Boolean And Operator
• Boolean Not Operator
• Python Boolean == (equivalent) and != (not equivalent) Operator
• Python is Operator
• Python in Operator
o Python List
▪ Creating a List
• Using Square Brackets
• Using the list() Constructor
▪ Creating a List with Repeated Elements
▪ Accessing List Elements
▪ Modifying Lists
▪ Adding Elements into List
• append()
• extend()
• insert()
▪ Updating Elements into List
▪ Removing Elements from List
• remove()
• pop()
• del statement
▪ Iterating Over Lists
• Using for Loop
• Using For-Loop and Range() Method
• Using While-Loop
• Using Enumerate()
• Using List Comprehension
• Using Iter and Next Functions
▪ Nested Lists and Multidimensional Lists
o Python Tuples
▪ Creating a Tuple
• Creating a Tuple with Mixed Datatypes.
▪ Python Tuple Operations
• Accessing of Python Tuples
• Concatenation of Tuples
• Slicing of Tuple
• Deleting a Tuple
▪ Built-In Methods
▪ Tuples VS Lists
o Python Sets
▪ Creating a Set in Python
• Creating a Python Set with Another Method
▪ Adding Elements to a Set in Python
• Using add() Method
• Using update() Method
▪ Accessing a Set in Python
▪ Removing Elements from the Set in Python
• Using remove() Method or discard() Method
• Using pop() Method
• Using clear() Method
▪ Frozen Sets in Python
▪ Typecasting Objects into Sets
▪ Advantages of Set in Python
• Unique Elements
• Fast Membership Testing
• Mathematical Set Operations
• Mutable
▪ Disadvantages of Sets in Python
• Unordered
• Limited Functionality
• Memory Usage
• Less Commonly Used
▪ Set Methods in Python
o Python Dictionary
▪ How to Create a Dictionary
▪ Accessing Dictionary Items
▪ Adding and Updating Dictionary Items
▪ Removing Dictionary Items
• del
• pop()
• clear()
• popitem()
▪ Iterating Through a Dictionary
• How to Loop Through a Dictionary in Python
o Iterate through Value
o Iterate through keys
o Iterate through both keys and values
o Iterating Python Dictionary Using map() and dict.get
o Iterate Python Dictionary using zip() Function
o Dictionary iteration in Python by unpacking the dictionary
▪ Nested Dictionaries
o Python Arrays
▪ Create an Array in Python
▪ Adding Elements to an Array
▪ Accessing Elements from Array
▪ Removing Elements from Array
▪ Slicing of an Array
▪ Searching Element in an Array
▪ Updating Elements in an Array
▪ Different Operations on Python Arrays
• Counting Elements in an Array
• Reversing Elements in an Array
• Extend Element from Array
• Type Casting
o There can be two types of Type Casting in Python
▪ Python Implicit Type Conversion
▪ Python Explicit Type Conversion
• Python Convert Int to Float
• Python Convert Float to Int
• Python Convert int to String
• Python Convert String to float
• Python Convert string to int

4. Python Operators

• Arithmetic Operators
o Addition Operator
o Subtraction Operator
o Multiplication Operator
o Division Operator
o Floor Division Operator
o Modulus Operator
o Exponentiation Operator
o Precedence of Arithmetic Operators in Python
o
• Comparison Operators
o Python Equality Operators a == b
o Inequality Operators a != b
o Greater than Sign a > b
o Less than Sign a < b
o Greater than or Equal to Sign x >= y
o Less than or Equal to Sign x <= y
o Chaining Comparison Operators
• Logical Operators
o Logical Operators in Python
▪ AND, Logical OR, and Logical NOT
▪ Order of Precedence of Logical Operators
▪ How do logical operators differ from bitwise operators in Python?
▪ Can logical operators be used with non-boolean values in Python?
• Bitwise Operators
o Bitwise AND Operator
o Bitwise OR Operator
o Bitwise XOR Operator
o Bitwise NOT Operator
o Bitwise Shift
▪ Bitwise Right Shift
▪ Bitwise Left Shift
o Bitwise Operator Overloading
o
• Assignment Operators
o Addition Assignment Operator
o Subtraction Assignment Operator
o Multiplication Assignment Operator
o Division Assignment Operator
o Modulus Assignment Operator
o Floor Division Assignment Operator
o Exponentiation Assignment Operator
o Bitwise AND Assignment Operator
o Bitwise OR Assignment Operator
o Bitwise XOR Assignment Operator
o Bitwise Right Shift Assignment Operator
o Bitwise Left Shift Assignment Operator
o Walrus Operator
• Membership & Identity Operators (in, is)
o Python Membership Operators
▪ Python IN Operator
▪ Python NOT IN Operator
o Python Identity Operators
▪ Python IS Operator
▪ Python IS NOT Operator
o Difference between ‘==’ and ‘is’ Operator

5. Python Conditional Statements

• if-else
o if Statement
o if….else Statement
• Nested if Statements
o if…elif…else Statement
• if-elif-else Ladder
o
• if-else on One Line
o Python Shorthandf If Else
o One Liner if elif else Statements
• Ternary Condition
o Python Ternary If Else
o Ternary Operator in Nested If else
o Ternary Operator using Python Tuple
o Ternary Operator using Python Dictionary
o Ternary Operator using Python Lambda
o Ternary Operator with Print Function
o Limitations of Python Ternary Operator
▪ Readability
▪ Potential for Error
▪ Debugging
▪ Maintenance and Extensibility
▪ Can’t use assignment statements
• Match Case Statement
o Python Match Case Statement Syntax
o Simple Match Case Statement
o Match Case Statement with OR Operator
o Match Case Statement with Python If Condition
o Match Case with the Sequence Pattern
o Match Case Statement with Python Dictionary
o Match Case Statement with Python Class

6. Python Loops

• for Loop
o How to use the for loop in Python
▪ Python For Loop with String
▪ Python for loop with Range
▪ Python for loop Enumerate
▪ Nested For Loops in Python
▪ Python For Loop Over List
▪ Python For Loop with Dictionary
▪ Python For Loop with Tuple
▪ Python For Loop with Zip()
o Control Statements that can be used with For Loop in Python
▪ Continue in Python For Loop
▪ Break in Python For Loop
▪ For Loop in Python with Pass Statement
▪ For Loops in Python with Else Statement

• while Loop
o Syntax of while loop in Python
o Python While Loop
o Infinite while Loop in Python
o Control Statements in Python with Examples
▪ Python while loop with continue statement
▪ Python while loop with a break statement
▪ Python while loop with a pass statement
▪ While loop with else
▪ Sentinel Controlled Statement
▪ Python while loop with user input
▪ While loop with Boolean values
▪ Python while loop with Python list
▪ Single statement while block
• Loop Control Statements (break, continue, pass)
o Break statement
▪ Syntax of Break Statement
▪ Working on Python Break Statement
o Continue statement
▪ Syntax of Continue Statement
▪ Working of Python Continue Statement
o Pass statement
▪ Syntax of Pass Statement
• List Comprehension
o Syntax of list comprehension
o for loop vs. list comprehension
o Conditional statements in list comprehension
• Dictionary Comprehension

7. Python Functions

• Global and Local Scope Variables


o Python Local Variables
▪ Creating local variables in Python
▪ Can a local variable be used outside a function?
o Python Global Variables
▪ Create a global variable in Python
o Why do we use Local and Global variables in Python?
o The global Keyword
o Difference b/w Local Variable Vs. Global Variables
• Use of pass Statement in Functions
o How to write an empty function in Python – pass statement?
• Return Statement
o Returning Multiple Values
▪ Using Tuple
▪ Using a list
▪ Using a Dictionary
o Function returning another function
o What will type() return in Python?
o
• range() Function
o Syntax of Python range() function
o What is the use of the range function in Python
▪ range (stop) takes one argument.
▪ range (start, stop) takes two arguments.
▪ range (start, stop, step) takes three arguments
o Incrementing the Range using a Positive Step
o Python range() using Negative Step
o Python range() with Float Values
• *args and **kwargs
o Special Symbols Used for passing arguments in Python:
▪ *args (Non-Keyword Arguments)
▪ **kwargs (Keyword Arguments)
o Using both *args and **kwargs in Python to call a function
o Using *args and **kwargs in Python to set values of object
▪ *args receives arguments as a tuple
▪ **kwargs receives arguments as a dictionary
• Python Closures
o Nested functions in Python
▪ What are Python Closures
▪ When and Why to Use Closures
• self as Default Argument
o Why Python Uses 'Self' as Default Argument
o Advantages
▪ Instance Clarity
▪ Attribute Access
▪ Encapsulation Aid
▪ Pythonic Convention
o Example of Using 'Self' As A Default Argument in Python
▪ Example 1: Object Initialization & Method Invocation
▪ Example 2: Circle Class for Area Calculation Example
• Decorators
o First Class Objects
o Properties of first-class functions
▪ Example 1: Treating the functions as objects.
▪ Example 2: Passing the function as an argument
▪ Example 3: Returning functions from another function.
o Decorators
▪ Syntax for Decorator
o What if a function returns something or an argument is passed to the function?
o Chaining Decorators
• map()
o Syntax of the map() function
o Converting map object to a list
o map() with lambda
o Using map() with multiple iterables
o Examples of map() function
o Converting to uppercase
o Extracting first character from strings
o Removing whitespaces from strings
o Calculate fahrenheit from celsius
• filter()
o Filter Function in Python with Lambda
▪ Python filter() Syntax
▪ Python Filter Function with a Custom Function
• reduce() Functions
o Using Operator Functions
▪ reduce() vs accumulate()
• Lambda Functions
o Python Lambda Function Syntax
o Use of Lambda Function in Python
▪ Condition Checking Using Python lambda function
▪ Difference Between Lambda functions and def defined function
o Practical Uses of Python lambda function
▪ Python Lambda Function with List Comprehension
▪ Python Lambda Function with if-else
▪ Python Lambda with Multiple Statements
o Using lambda() Function with filter()
▪ Filter out all odd numbers using filter() and lambda function
▪ Filter all people having age more than 18, using lambda and filter() function
o Using lambda() Function with map
▪ Multiply all elements of a list by 2 using lambda and map() function
▪ Transform all elements of a list to upper case using lambda and map() function
o Using lambda() Function with reduce()
▪ A sum of all elements in a list using lambda and reduce() function
▪ Find the maximum element in a list using lambda and reduce() function

8. Access Modifiers in Python : Public, Private and Protected


• Underscore (_) in Python
o Single Underscore
▪ Single Underscore in Interpreter
▪ Single Underscore for ignoring values
▪ Single Underscore after a name
▪ Single Underscore before a name
▪ Single underscore in numeric literals
o Double Underscore
▪ Double underscore before a name
▪ Double underscore before and after a name

8. Python OOPs Concepts

• Python Classes and Objects


o Creating a Python Class
o Object of Python Class
o Declaring Class Objects (Also called instantiating a class)
▪ Self Parameter
▪ Pass Statement
▪ __init__() method
▪ __str__() method
o Class and Instance Variables
▪ Defining instance variables using a constructor
▪ Defining instance variables using the normal method
• Polymorphism
o What is Polymorphism
o Polymorphism with class methods
o Polymorphism with Inheritance
o Polymorphism with a Function and objects
• Inheritance
o Benefits of inheritance are
o Python Inheritance Syntax
▪ Creating a Parent Class
▪ Creating a Child Class
o Example of Inheritance in Python
o What is an object class in Python?
▪ Using Object Class Methods
• toString() method
• hashCode() method
• equals(Object obj) method
• finalize() method
• getClass() method
• clone() method
• wait(), notify() notifyAll() methods
▪ Subclassing (Calling constructor of parent class)
▪ The super() Function
▪ Adding Properties
▪ Different types of Python Inheritance
• Single inheritance
• Multiple inheritances
• Multilevel inheritance
• Hierarchical inheritance
• Hybrid inheritance
▪ Private members of the parent class
• Abstract Classes
o Abstract Base Classes in Python
o Working on Python Abstract classes
▪ Implementation of Abstract through Subclass
▪ Concrete Methods in Abstract Base Classes
▪ Abstract Properties in Python
▪ Abstract Class Instantiation
• Encapsulation
o Protected members
o Private members
• Iterators
o __iter__()
o __next__()
o Iterating over built-in iterable using iter() method
▪ Iterable vs Iterator
▪ Iterating on an Iterable
o Getting StopIteration Error while using iterator

9. Python Exception Handling

• Python File Handling


o Advantages of File Handling in Python
▪ Versatility
▪ Flexibility
▪ User – friendly
▪ Cross-platform
o Disadvantages of File Handling in Python
▪ Error-prone
▪ Security risks
▪ Complexity
▪ Performance
• Working in Read mode
o Reading Files
o Writing/Creating Files
▪ Access Mode
▪ Opening a File
▪ Closing a file
▪ Writing to file
▪ Appending to a file
▪ With statement
• Exception Handling
o Different types of exceptions in python
▪ SyntaxError
▪ TypeError
▪ NameError
▪ IndexError
▪ IndexError
▪ KeyError
▪ ValueError
▪ AttributeError
▪ IOError
▪ ZeroDivisionError
▪ ImportError
o Difference between Syntax Error and Exceptions
o Try and Except Statement – Catching Exceptions
o Catching Specific Exception
o Try with Else Clause
o Finally Keyword in Python
o Raising Exception
o Advantages of Exception Handling
▪ Improved program reliability
▪ Simplified error handling
▪ Cleaner code
▪ Easier debugging
o Disadvantages of Exception Handling
▪ Performance overhead
▪ Increased code complexity
▪ Possible security risks

• User-Defined Exceptions
o Customizing Exception Classes
▪ Example 1: User-Defined class with Multiple Inheritance
▪ Example 2: Deriving Error from Super Class Exception
o How to use standard Exceptions as a base class?
• Built-In Exceptions
o Base Classes
▪ exception BaseException
▪ exception Exception
▪ exception ArithmeticError
• OverflowError
• ZeroDivisionError
• FloatingPointError
▪ exception BufferError
▪ exception LookupError
• KeyError
• IndexError
▪ Concrete exceptions
• exception AssertionError
• exception AttributeError
• exception EOFError
• exception FloatingPointError
• exception GeneratorExit
• exception ImportError
• exception ModuleNotFoundError
• exception IndexError
• exception KeyError
• exception KeyboardInterrupt
• exception MemoryError
• exception NameError
• exception NotImplementedError
• exception OSError([arg])
• exception OverflowError
• exception RecursionError
• exception ReferenceError
• exception RuntimeError
• exception StopIteration
• exception SyntaxError
• exception SystemExit
• exception TypeError
• exception UnboundLocalError
• exception UnicodeError
• exception ValueError
• exception ZeroDivisionError
• try and except Blocks
o Some of the common Exception Errors are :
o Try Except in Python
o How try() works?
o Else Clause
o Finally Keyword in Python
10. Python Packages or Libraries

• Built-in Modules
• Python DSA Libraries
• Machine Learning Libraries
• Python GUI Libraries
• Web Scraping Packages
• Game Development Packages
• Web Frameworks (Django, Flask)
• Image Processing Libraries (OpenCV, Pillow)

11. Python Collections

• Counters
• Heapq
• Deque
• OrderedDict
• Defaultdict

You might also like