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

Make A Combine Table of All The 4

The document presents a combined table summarizing basic functions for strings, lists, dictionaries, and tuples in Python, detailing their uses and providing examples. Each data type is associated with specific functions such as lower(), append(), keys(), and index(), among others. This overview serves as a quick reference for common operations on these data types.

Uploaded by

arpitadutta.2507
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)
5 views3 pages

Make A Combine Table of All The 4

The document presents a combined table summarizing basic functions for strings, lists, dictionaries, and tuples in Python, detailing their uses and providing examples. Each data type is associated with specific functions such as lower(), append(), keys(), and index(), among others. This overview serves as a quick reference for common operations on these data types.

Uploaded by

arpitadutta.2507
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

make a combine table of all the 4

Here is a combined table summarizing basic functions for strings, lists, dictionaries, and tuples in
Python, along with their uses and examples:

Functions Data Type Uses Example

lower() String Converts a string to lowercase. "Hello".lower() returns "hello".

upper() String Converts a string to uppercase. "hello".upper() returns "HELLO".

Removes leading and trailing


strip() String " hello ".strip() returns "hello".
whitespace.

Splits a string into a list based "hello world".split(" ") returns


split() String
on a delimiter. ["hello", "world"].

Concatenates strings in an ",".join(["hello", "world"]) returns


join() String
iterable with a delimiter. "hello,world".

Replaces a substring with "hello world".replace("world",


replace() String
another string. "earth") returns "hello earth".

Returns the index of the first


find() String "hello world".find("world") returns 6.
occurrence of a substring.

Checks if a string starts with a "hello world".startswith("hello")


startswith() String
specified prefix. returns True.

Checks if a string ends with a "hello world".endswith("world")


endswith() String
specified suffix. returns True.

Returns the number of "hello hello".count("hello") returns


count() String
occurrences of a substring. 2.

Adds an element to the end of my_list = []; my_list.append(3)


append() List
the list. results in ``.

Adds multiple elements to the my_list = []; my_list.extend()


extend() List
end of the list. results in ``.

Inserts an element at a my_list = []; my_list.insert(0, 1)


insert() List
specified position. results in ``.

Removes the first occurrence my_list =; my_list.remove(1) results


remove() List
of a specified element. in ``.

Removes and returns an


my_list =; my_list.pop(0) returns 1
pop() List element at a specified position
and results in ``.
(default is the last element).
Functions Data Type Uses Example

Returns the index of the first


index() List occurrence of a specified my_list =; my_list.index(1) returns 0.
element.

Returns the number of


count() List occurrences of a specified my_list =; my_list.count(1) returns 2.
element.

sort() List Sorts the list in-place. my_list =; my_list.sort() results in ``.

my_list =; my_list.reverse() results


reverse() List Reverses the list in-place.
in ``.

Removes all elements from the my_list =; my_list.clear() results in


clear() List
list. [].

Returns a view object that


my_dict = {"a": 1};
keys() Dictionary displays a list of all keys in the
list(my_dict.keys()) returns ["a"].
dictionary.

Returns a view object that


my_dict = {"a": 1};
values() Dictionary displays a list of all values in
list(my_dict.values()) returns ``.
the dictionary.

Returns a view object that my_dict = {"a": 1};


items() Dictionary displays a list of all key-value list(my_dict.items()) returns [("a",
pairs in the dictionary. 1)].

Returns the value for a given my_dict = {"a": 1};


get() Dictionary key if it exists in the dictionary. my_dict.get("a", "Not found")
If not, it returns a default value. returns 1.

Updates the dictionary with the


my_dict = {"a": 1};
items from another dictionary
update() Dictionary my_dict.update({"b": 2}) results in
or from an iterable of key-value
{"a": 1, "b": 2}.
pairs.

Removes and returns the value


my_dict = {"a": 1};
of a specified key. If the key
pop() Dictionary my_dict.pop("a") returns 1 and results in
does not exist, it returns a
{}.
default value.

Removes and returns the last


my_dict = {"a": 1};
inserted item (in Python 3.7
popitem() Dictionary my_dict.popitem() returns ("a", 1) and
and later, insertion order is
preserved). results in {}.

Removes all items from the my_dict = {"a": 1};


clear() Dictionary
dictionary. my_dict.clear() results in {}.

Returns a copy of the my_dict = {"a": 1}; my_dict.copy()


copy() Dictionary
dictionary. returns {"a": 1}.

Returns the index of the first


my_tuple = (1, 2);
index() Tuple occurrence of a specified
my_tuple.index(1) returns 0.
element.
Functions Data Type Uses Example

Returns the number of


my_tuple = (1, 1);
count() Tuple occurrences of a specified
my_tuple.count(1) returns 2.
element.

Returns the number of my_tuple = (1, 2); len(my_tuple)


len() Tuple
elements in the tuple. returns 2.

Returns the largest item in the my_tuple = (1, 2); max(my_tuple)


max() Tuple
tuple. returns 2.

Returns the smallest item in my_tuple = (1, 2); min(my_tuple)


min() Tuple
the tuple. returns 1.

Returns the sum of all my_tuple = (1, 2); sum(my_tuple)


sum() Tuple
elements in the tuple. returns 3.

Returns True if at least one my_tuple = (False, True);


any() Tuple
element of the tuple is true. any(my_tuple) returns True.

all() Tuple Returns True if all elements of my_tuple = (True, True);


the tuple are true. all(my_tuple) returns True.

Converts an iterable (like a list my_list =; tuple(my_list) returns (1,


tuple() Tuple
or string) into a tuple. 2).

This table provides a comprehensive overview of common functions for each data type in
Python.

You might also like