0% found this document useful (0 votes)
5 views9 pages

Functions and Collections Python Presentation

Functions in Python are defined blocks of code that perform specific tasks, improving modularity and reducing repetition. Collections are used to store multiple items, with four main types: List, Tuple, Set, and Dictionary, each having unique characteristics. Lists are ordered and mutable, Tuples are ordered and immutable, Sets are unordered and mutable, and Dictionaries store key-value pairs.

Uploaded by

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

Functions and Collections Python Presentation

Functions in Python are defined blocks of code that perform specific tasks, improving modularity and reducing repetition. Collections are used to store multiple items, with four main types: List, Tuple, Set, and Dictionary, each having unique characteristics. Lists are ordered and mutable, Tuples are ordered and immutable, Sets are unordered and mutable, and Dictionaries store key-value pairs.

Uploaded by

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

Functions and Collections in

Python
What are Functions in Python?

• Functions are blocks of code that perform a


specific task.
• They help to reduce repetition and improve
modularity.
• Defined using the 'def' keyword.
• Can take inputs (parameters) and return
outputs.
Function Syntax and Example

• Syntax: def function_name(parameters):


• Example:

def greet(name):
print('Hello', name)
greet(‘kevin')
Types of Functions

• Built-in Functions: print(), len(), type()


• User-defined Functions: Functions you define
• Functions with Arguments and Return Values
• Lambda (Anonymous) Functions
• Default and Keyword Arguments
What are Collections in Python?

• Collections are used to store multiple items in


a single variable.
• Python has four main collection types: List,
Tuple, Set, Dictionary.
• Each collection type has different features and
use-cases.
List

• Ordered, mutable, allows duplicates.


• Defined using square brackets [].
• Example: fruits = ['apple', 'banana']
• Supports methods like append(), remove(),
sort().
Tuple

• Ordered, immutable, allows duplicates.


• Defined using parentheses ().
• Example: colors = ('red', 'blue')
• Used when data should not change.
Set

• Unordered, mutable, does not allow


duplicates.
• Defined using curly braces {}.
• Example: nums = {1, 2, 2, 3} -> {1, 2, 3}
• Supports operations like union, intersection.
Dictionary

• Unordered collection of key-value pairs.


• Defined using curly braces {} with colons.
• Example: student = {'name': 'Tom', 'age': 20}
• Access values using keys, e.g., student['name']

You might also like