Sumit
@B2B_Threads
Followers
0
Following
0
Media
23
Statuses
89
Data analysis || Digital marketing || Graphic design
Joined September 2024
Why Use Functions? 🔹 Code Reusability – Write once, use multiple times. 🔹 Improved Readability – Modular code structure. 🔹 Easier Debugging – Isolate logic into functions. 🔹 Scalability – Manage complex programs efficiently. What Can Be Used in a def Function?
1
0
0
Docstring (optional) – A multi-line string describing what the function does. Function body – The indented block of code that executes when the function is called. return statement (optional) – Specifies the output of the function.
1
0
0
Key Components of a Function def keyword – Indicates the start of a function definition. Function name – A unique identifier for the function (follows Python naming conventions). Parameters (optional) – Inputs that the function can accept (enclosed in parentheses).
1
0
0
In Python, the def keyword is used to define a function, which is a reusable block of code that performs a specific task. Functions allow you to write cleaner, more organized, and efficient code by avoiding repetition.
1
0
0
To save our time we use Loop #function and it comes with many sub function like IF, ELIF, ELSE, Range, Break & Continue, While for explanation is given in .
1
0
0
where, My_List = [1, 2, 3, 4, 5] print(My_List) this can give us data of whole list but this method don't give us data in indexing and it time consuming to write print function many time so to save time what function we can use?
1
0
0
5 Get the top 5 students with the highest grades 6 Find the student with the lowest grade 7 Show all students whose names start with 'A' 8 List students aged between 20 and 22, sorted by grade in descending order 9 Calculate the total number of students in each city.
0
0
1
1 We have a simple table of 15 students with fields like id, name, age, grade, and city 1 Find all students with grades above 85 2 List the names of students from 'New York' 3 Find the average grade of students aged 22 4 Count how many students are from 'Chicago'
1
0
0
Set Syntax: {} A set in Python is an unordered collection of unique elements. Sets are useful when you want to store items without duplicates and perform mathematical operations like union, intersection, and difference.
1
0
0
Key Features: Key-Value Pairs: Each key maps to a specific value. Keys Are Unique: No duplicate keys are allowed, but values can be duplicated. Unordered (before Python 3.7): As of Python 3.7+, dictionaries maintain insertion order, but you still can't access items by index.
1
0
0
Dictionary Syntax {key1:value1} A dictionary in Python is an unordered, mutable collection of key-value pairs. Dictionaries are very efficient for looking up values based on their keys and are widely used when you need to associate data.
1
0
0
Key Features: Ordered: Elements have a defined order and can be accessed by their index. Immutable: Cannot modify (add, remove, or change) elements after creation. Allow Duplicates: Can contain repeated values. Can Contain Mixed Data Types: Can store different types of data .
1
0
0
tuple Syntax () A tuple in Python is an immutable, ordered collection of elements. This means that once a tuple is created, its elements cannot be changed, added, or removed. Tuples can contain elements of different data types, such as integers, strings, lists, or other tuples.
1
0
0
Key Features: Ordered: Elements maintain the order in which they were added. Mutable: You can add, remove, or change elements after the list is created. Allow Duplicates: Lists can contain repeated values. Can Contain Mixed Data Types: A list can store integers, strings, floats.
1
0
0
List Syntax [] A list in Python is an ordered, mutable (changeable) collection of elements. Lists are one of the most commonly used data structures in Python because they are flexible and easy to use.
1
0
0