Python String

Python contains many useful built-in functions and methods to accomplish common tasks.

join – joins a list of strings with another string as a separator.
replace – replaces one substring in a string with another.
startswith and endswith – determine if there is a substring at the start and end of a string, respectively.
To change the case of a string, you can use lower and upper.
The method split is the opposite of join turning a string with a certain separator into a list.

To find the maximum or minimum of some numbers or a list, you can use max or min.
To find the distance of a number from zero (its absolute value), use abs.
To round a number to a certain number of decimal places, use round.
To find the total of a list, use sum.
Some examples:

Example print(min([sum([11,22]),max(abs(-30),2)]))
output : 30

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started