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

Bulit in Functions Seprated According to Data Type

The document provides an overview of four fundamental data structures in Python: lists, dictionaries, tuples, and strings, along with their definitions and built-in operations. Lists are mutable collections, dictionaries are unordered key-value pairs, tuples are immutable collections, and strings are immutable sequences of characters. Each section includes methods and their descriptions for manipulating these data structures.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Bulit in Functions Seprated According to Data Type

The document provides an overview of four fundamental data structures in Python: lists, dictionaries, tuples, and strings, along with their definitions and built-in operations. Lists are mutable collections, dictionaries are unordered key-value pairs, tuples are immutable collections, and strings are immutable sequences of characters. Each section includes methods and their descriptions for manipulating these data structures.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

List Method Description


Definition: islower() / isupper() Case check
A list is an ordered, mutable (changeable) collection of len(string) (function) Returns length
elements.
my_list = [1, 2, 3, 4]
4. Dictionary
Built-in Operations for Lists:
Definition:
Method Description
A dictionary is an unordered collection of key-value pairs.
append(x) Adds element at the end my_dict = {"name": "Alice", "age": 25}
insert(i, x) Inserts x at position i Built-in Operations for Dictionaries:
extend(iter) Appends elements from another iterable Method Description
remove(x) Removes first occurrence of x get(key) Returns value or None if key not found
Removes and returns item at index i (or last if keys() Returns all keys
pop([i])
not given) values() Returns all values
clear() Removes all items items() Returns key-value pairs
index(x) Returns first index of x update(other_dict) Updates with another dictionary
count(x) Returns count of x pop(key) Removes key and returns its value
sort() Sorts the list (in-place) popitem() Removes and returns last inserted pair
reverse() Reverses the list (in-place) clear() Removes all items
copy() Returns a shallow copy setdefault(key, val) Returns value if key exists, else sets it
copy() Returns shallow copy
2. Tuple
len(dict) (function) Returns number of key-value pairs
Definition:
A tuple is an ordered, immutable collection of elements.
my_tuple = (1, 2, 3, 4)
Built-in Operations for Tuples:
Method Description
count(x) Returns number of occurrences of x
index(x) Returns first index of x
Tuples are immutable, so no add/remove/sort/change
methods.

3. String
Definition:
A string is an immutable sequence of characters.
my_string = "hello world"
Built-in Operations for Strings:
Method Description
lower() Converts to lowercase
upper() Converts to uppercase
capitalize() Capitalizes first letter
title() Capitalizes first letter of every word
strip() Removes leading/trailing whitespaces
replace(old, new) Replaces substring
split(separator) Splits string into list
join(iterable) Joins iterable into string
find(sub) Returns first index of sub or -1
index(sub) Like find, but raises error if not found
count(sub) Counts occurrences of sub
startswith(prefix) Checks if starts with prefix
endswith(suffix) Checks if ends with suffix
isalpha() Checks if all chars are alphabetic
isdigit() Checks if all chars are digits
isalnum() Checks if all chars are alphanumeric

You might also like