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

python string list dict set methods

The document provides a comprehensive overview of various Python string, set, list, and dictionary methods, detailing their functionalities and optional parameters. Each method is briefly described, highlighting its purpose and usage. The document serves as a reference guide for Python programming, particularly for manipulating data structures.

Uploaded by

slymnshn8690
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 views4 pages

python string list dict set methods

The document provides a comprehensive overview of various Python string, set, list, and dictionary methods, detailing their functionalities and optional parameters. Each method is briefly described, highlighting its purpose and usage. The document serves as a reference guide for Python programming, particularly for manipulating data structures.

Uploaded by

slymnshn8690
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/ 4

capitalize casefold center count

Returns centred string using optional value as fill Return no of times value is in string. Optional parameters
Convert first character to upper case and rest lowercase Convert string to lower case. More aggresive than lower() character. Space (" ") is default specify where to search in string

encode endswith expandtabs find


Return encoded version of string. Optional parameter Set tab size of string to specified number of Return position of value if found in string. -1 returned if string not
encoding & errors specify encoding to use and error method Return true if string ends with value whitespaces. Default is 8 found. 2 optional params specifying where to start & end search

format format_map index isalnum


Return position of value if found in string. Raise exception if not
Format values in string Format values in string using map-based substitution found. 2 optional params specifying where to start & end Return true if all string characters are alphanumeric
search

isalpha isascii isdecimal isdigit


Return true if all string characters are decimals (0-9).
Return true if all string characters are in alphabet Return true if all string characters are ascii Can work on Unicode. Only supports decimals Return true if all string characters are digits

isidentifier isnumeric isprintable islower


Return true if string is an identifer. These can only contain
alphanumeric chars & underscores & can't start with numbers Return true if all characters are numeric Return true if all characters are printable Return true if all characters are lower case

isspace isupper
Return true if all characters are whitespaces
Return true if all characters are upper case

istitle
Python join
Return true if string follows rules of a title (all words are
lowercase except the first letter of each word) STRING METHODS Join iterable elements to end of stiring

By @AbzAaron

ljust lower lstrip maketrans


Return string left justified. 2nd optional param specifies Return translation table that can be used with
character to fill space. Default is space. Convert string to lower case Same as strip but only leading chars translate().Check docs for more details on maketrans()

partition replace rfind rindex


Return tuple with string parted in 3 parts. Middle part is Return string where one value is replaced with another.
specified string. If not found, entire string stored in first part of Optional parameter specifies how many occurrences to replace Same as find but searches for last occurrence of string Same as index but searches for last occurence of string
tuple

rjust rpartition rsplit rstrip


Return string right justified. 2nd optional param specifies
character to fill space. Default is space. Same as partition but searches for last occurence of string Same as split but starts from the right Same as strip but only trailing chars

split splitlines startswith strip


Split string at whitespace and return list. 2 optional params Split string at linebreaks and return list. Optional param Remove leading & trailing chars. Optional param
allow you to specify separator and how many splits to do. determines whether to include line break after split Return true if string starts with value specifies chars to remove as leading/trailing chars

swapcase title translate upper


Returns a translated string using mapping table, or
Swap cases (e.g. lowercase become upper) Covert first character of each word to upper case dictionary with ascii characters Convert characters to uppercase

zfill removeprefix removesuffix Consider


Fills string with specified number of 0 values at start Return string without specified prefix. Only Python 3.9+ Return string without specified suffix. Only Python 3.9+ Supporting Me!

@AbzAaron
Set Methods
Sets are unordered & mutable collections of
unique elements

add clear copy


Add an element to Set. Will not add if element Remove all elements in set Return copy of set
already exists

difference difference_update discard


Return set with difference between two sets. Same as difference but removes unwanted Remove item from set. Will not throw error if
i.e. exist only in the first set & not in both sets items instead of returning new set item doesn't exist

intersection intersection_update isdisjoint


Return set containing only items that exist in Same as intersection but removes unwanted Return True if none of the items are in
all sets. Can pass multiple parameters items instead of returning new set both sets

issubset issuperset pop


Return True if all items in original set Return True if all items in specified set Remove and return random item from set
exist in specified set exist in original set

remove symmetric_difference symmetric_difference_update


Same as discard but will raise error if item Return set containing all items from both Same as symmetric_difference but updates the
does not exist sets, but not those present in both sets original set rather than returning new one

union update
Return set containing items from original set & Update original set by adding items from
items from specified set(s) or iterable(s) another set or iterable

Reference Feel Free to


Buy Me A
W3Schools.com Coffee
By @AbzAaron
PYTHON
List Methods @AbzAaron

APPEND
Add single element to
end of list

CLEAR
Remove all Items from
list

COPY
Return shallow copy of
list

COUNT
Return count of an
element in list

EXTEND
Adds iterable elements
to end of list

INDEX
Return index of first element
in list matching given value

INSERT
Insert element to list at
given index

POP
Remove element at given
index and returns it

REMOVE
Remove first item from
list that has given value

REVERSE
Reverse the list

SORT
Sort elements of a list
PYTHON
Dictionary Methods
@AbzAaron

CLEAR
Remove all elements from Dictionary

COPY
Return copy of Dictionary

FROMKEYS
Return Dictionary with specified keys &
values
Optional Parameter: Value. This is what's set for all keys.
Default is None

GET
Return value of specified key

Optional Parameter: Value. Value returned if no key exists.


Default is None

ITEMS
Return view object containing list of
key value pairs

KEYS
Return view object containing list of
keys

POP
Remove element with specified key
and return it
Optional Parameter: Defaultvalue. This is value to return if no key is
found in dictionary

POPITEM
Remove last inserted key value pair and
return as tuple

Python < 3.7 method returns random item

SETDEFAULT
Return value of item with specified key. If
key doesn't exist, insert with specified value
Optional Parameter: value. Default is None

UPDATE
Update dictionary with specified key
value pairs

VALUES
Return view objects containing list of
values

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy