Posts

Showing posts from August, 2025

Built-in data Structures

  Built-in Data Structures List A  list  in Python is a  mutable, ordered collection  used to store multiple items in a single variable. It is one of the most commonly used data structures in Python. Key Characteristics of Lists Ordered Items are stored in the order they are added. The order is preserved unless explicitly modified. Mutable Lists can be changed after creation. You can: Add ( append() ,  insert() ,  extend() ) Remove ( remove() ,  pop() ,  del ) Modify items ( list[index] = new_value ) Heterogeneous A list can store elements of different data types: my_list = [ 42 , "hello" , 3.14 , [ 1 , 2 ]] Indexed Elements are accessed by position (index), starting at 0: print (my_list[ 0 ]) # Output: 42 Dynamic Size Lists can grow or shrink in size dynamically as elements are added or removed. List Accessing: In Python, you access list elements using  indexing  or  slicing . 1. Indexing We can use the index operator [] to ...

FUNCTIONS, PYTHON OOPS AND EXCEPTION HANDLING

Image
FUNCTIONS, PYTHON OOPS AND EXCEPTION HANDLING Functions A function is a block of statements   used to perform a specific task. Functions allow us to divide a larger problem into smaller subparts to solve efficiently, to implement the code reusability concept and makes the code easier to read and understand.  Types of Functions in Python: 1.  Built-in Functions These are the functions that come pre-defined with Python. They help perform common tasks like printing, taking input, working with numbers or sequences, etc. Examples: Function Description Example print() Displays output on the screen print("Hello") len() Returns the length of an object len("Python") type() Returns the type of an object type(5) int() Converts to integer int("10") float() Converts to float float("3.14") str() Converts to string str(100) input() Takes input from the user input("Enter name: ") sum() Returns the sum of el...