0% found this document useful (0 votes)
3 views2 pages

Python Data Types Methods

The document outlines various Python data types including strings, lists, tuples, sets, and dictionaries, along with their methods and operations. Each data type is categorized with specific methods for accessing, modifying, and analyzing data. Key functionalities such as adding, removing, searching, and manipulating data are highlighted for each type.

Uploaded by

ayush63537
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)
3 views2 pages

Python Data Types Methods

The document outlines various Python data types including strings, lists, tuples, sets, and dictionaries, along with their methods and operations. Each data type is categorized with specific methods for accessing, modifying, and analyzing data. Key functionalities such as adding, removing, searching, and manipulating data are highlighted for each type.

Uploaded by

ayush63537
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/ 2

Python Data Types Methods & Operations

1. STRING

Category Method/Operation Description

Access str[index] Access character at index

Slicing str[start:end] Returns substring from start to end-1

Case Change str.upper() Converts to uppercase

Case Change str.lower() Converts to lowercase

Case Change str.title() Capitalizes each word

Search str.find(sub) Returns index of first occurrence, -1 if not found

Replace str.replace(a, b) Replaces a with b

Check Type str.isalpha() All characters are alphabetic

Split & Join str.split(sep) Splits by separator

Strip str.strip() Removes spaces from both ends

Others len(str) Length of string

2. LIST

Category Method/Operation Description

Access list[index] Access element at index

Add list.append(x) Adds item to end

Add list.insert(i, x) Inserts at index

Remove list.remove(x) Removes first occurrence of x

Remove list.pop([i]) Removes and returns item at index

Search list.index(x) Returns first index of x

Sort/Reverse list.sort() Sorts in place

Copy list.copy() Returns shallow copy

Others len(list) Number of items

3. TUPLE

Category Method/Operation Description

Access tuple[index] Access element at index

Count tuple.count(x) Counts occurrences of x

Index tuple.index(x) Returns first index of x

Others len(tuple) Number of items


Python Data Types Methods & Operations

Immutability - Tuples cannot be modified

4. SET

Category Method/Operation Description

Add/Remove set.add(x) Adds item

Remove set.remove(x) Removes x (error if not found)

Combine Sets set.union(s2) Returns union

Combine Sets set.update(s2) Adds elements from s2

Check set.issubset(s2) True if set is subset

Others len(set) Number of items

5. DICTIONARY

Category Method/Operation Description

Access dict[key] Get value for key

Add/Update dict[key] = value Adds/updates key

Remove dict.pop(key) Removes key and returns value

Keys/Values dict.keys() Returns all keys

Set Default dict.setdefault(k, v) Sets value if key not in dictionary

Update dict.update(d2) Updates from another dict

Others len(dict) Number of key-value pairs

You might also like