0% found this document useful (0 votes)
6 views

Python Notes | 6th Sem | NEP2022

This document provides detailed notes on Python covering two units: Python Basics and Functions and Lists. Unit I discusses the origins, structure, syntax, and basic operations in Python, while Unit II focuses on functions, parameters, return values, and list operations. Key concepts include variable scope, list methods, and list comprehension.

Uploaded by

irfanrehman.edu
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)
6 views

Python Notes | 6th Sem | NEP2022

This document provides detailed notes on Python covering two units: Python Basics and Functions and Lists. Unit I discusses the origins, structure, syntax, and basic operations in Python, while Unit II focuses on functions, parameters, return values, and list operations. Key concepts include variable scope, list methods, and list comprehension.

Uploaded by

irfanrehman.edu
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/ 3

PYTHON | 5269 | 6TH Sem | IRFAN REHMAN

Detailed Python Notes - UNIT I & II


UNIT I: Python Basics (15 Lectures)

1. Origins and History of Python


Python was created by Guido van Rossum and released in 1991. It was designed with code readability in mind, and
its syntax allows programmers to express concepts in fewer lines of code.

2. Structure of a Python Program


A Python program may contain import statements, function definitions, and a main block for execution using if
__name__ == '__main__'.

3. Interpreter Shell
Python provides an interactive shell where you can type code line by line and see immediate results, useful for
testing and debugging.

4. Indentation
Python uses indentation (whitespace) to define blocks of code. It replaces the use of curly braces as in other
languages.

5. Comments
Single-line comments start with #. Multi-line comments use triple quotes (''' or ").

6. Identifiers and Keywords


Identifiers are names used to identify variables, functions, etc. Keywords are reserved words like 'if', 'for', 'def', etc.,
that have special meaning in Python.

7. Literals
Literals are fixed values assigned to variables, such as numeric (int, float), string, boolean, and special literals like
None.

8. Basic Operators
Python includes Arithmetic (+, -, *, /), Relational (==, !=), Logical (and, or, not), Assignment (=, +=), and Bitwise (&,
|, ^) operators.

9. Expressions and Data Types


Expressions combine variables and operators. Data types include integers, floats, strings, and complex numbers.

10. String Operations


Strings can be concatenated using +, replicated using *, and accessed using indexing and slicing.

PYTHON | 5269 | 6TH Sem | IRFAN REHMAN


PYTHON | 5269 | 6TH Sem | IRFAN REHMAN

11. Variables
Variables are containers for storing data values. They are dynamically typed, meaning their type is inferred.

12. Input and Output


input() is used to take input from the user. print() is used to display output.

13. Control Statements


Includes conditional statements (if, if-else), loops (for, while), and loop controls (break, continue, pass). range()
generates sequences for loops.

UNIT II: Functions and Lists (15 Lectures)

1. Functions
Functions are reusable blocks of code defined using the def keyword. They perform specific tasks and can be called
multiple times.

2. Parameters and Arguments


Functions accept input values called parameters. Arguments are values passed during function calls. Types include
positional, keyword, default, and variable-length arguments.

3. Return Values
Functions can return results to the caller using the return statement. If no return is used, the function returns
None.

4. The None Value


None is a special constant in Python representing the absence of a value or a null value.

5. Scope of Variables
Local scope means a variable is accessible only inside its function. Global scope means a variable is accessible
throughout the program. Use the global keyword to modify global variables inside functions.

6. The global Statement


The global statement is used inside functions to declare that a variable is global, allowing it to be modified.

7. The List Data Type


Lists are ordered and mutable collections of items. They can contain different data types and are defined using
square brackets [].

8. Basic List Operations


Lists support operations like concatenation (+), repetition (*), membership testing (in), and length calculation
(len()).

PYTHON | 5269 | 6TH Sem | IRFAN REHMAN


PYTHON | 5269 | 6TH Sem | IRFAN REHMAN

9. Indexing and Slicing in Lists


Lists use zero-based indexing. Slicing allows accessing sub-parts of lists using [start:end:step].

10. Built-In Functions Used on Lists


Includes functions like len(), max(), min(), sum(), and sorted() for performing operations on lists.

11. List Methods


Common methods include append(), extend(), insert(), remove(), pop(), index(), count(), reverse(), and sort().

12. List Comprehension


A concise way to create lists: [expression for item in iterable if condition]. Example: [x*x for x in range(10)]

PYTHON | 5269 | 6TH Sem | IRFAN REHMAN

You might also like