String Methods
str.isdigit() |
Returns Boolean |
"24".isdigit() |
str.title() |
Capitalize Every First Letter |
"hello world".title() |
str.lower() |
Lowercase first Letter |
"Hello World".lower() |
str.upper() |
Capitalizes First letter |
"hello world".upper() |
str.startswith(prefix[, start[, end]]) |
Returns Boolean |
"Hello World".startswith("Hello") |
str.split(sep=None, maxsplit=-1) |
Returns a list |
"The, fox, is, crazy".split(',') |
str.join(iterable) |
Glues an iterable together with a string |
"\n".join(["Three", "new", "Lines"]) |
str.endswith(prefix[, start[, end]]) |
Returns a Boolean |
"Hello World".endswith("World") |
str.replace(old, new[, count]) |
Returns a new string |
"Hello n World".replace("n", "and") |
str.format(args, *kwargs) |
Insert args/kwargs into a string |
"The {} jumped {}.".format(animal, height) |
Built-in Functions
all(iterable) |
Check if all elements are True. Returns boolean. |
all([True, True, True)] |
any(iterable) |
Check if any element is True. Returns Boolean |
any([True, False, False]) |
divmod(a, b) |
Returns quotient and remainder |
quotient, remainder = divmod(24, 7) |
int() |
Returns an integer |
int("24") |
max() |
Returns largest item in an iterable |
max([1, 10, 4]) |
map() |
Returns a map object with a function applied to each element |
map(str, [1, 2, 3]) |
min() |
Returns smallest item in an iterable |
min([1, 10, 4]) |
reversed() |
Reverse order of a squence |
reverse([1, 2, 3, 4]) |
sorted(iterable[, key][, reverse]) |
Returns new iterable sorted by specification |
sorted([5, 2, 3, 1, 4]) |
str() |
Returns a string |
str(24) |
sum(iterable[, start]) |
Returns the sum of an iterable |
sum([1, 2, 3, 4]) |
zip(*iterables) |
Creates a sequence, where each corresponding element is paired |
zip([1, 2, 3], [4, 5, 6]) |
|
|
Reminders
Watch out for python 2.7 code and libraries. They are not compatible with Python 3 |
Ints, Floats, Complex, Booleans, Strings, Tuples, and bytes are immutable |
Dictionaries are by default unordered prior to Python 3.6 |
Readability is more important than speed 95% of the time |
Always put a space between operators: 5 + 3 |
Use is instead of == when checking for None. |
Don't use blind excepts in try/except blocks. |
Everything is a public method. Nothing is completely private. |
Find out what tools are available in the standard library. Don't reinvent the wheel. |
Don't over optimize your code when writing it for the first time. |
List, Generator, and Dictionary comprehensions are your friends. Don't make them an enemy through over complication. |
Remember T3. Test, Test, Test. |
Refactor your code after your have finished writing it the first time. |
The differences in polling/blocking vs non-polling/non-blocking |
|
|
|