Find and return index of first occurance of needle
, or -1 if not found.
str.find(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
str needle |
"abc".find("b") == 1 == True
Index - int
Replace all occurances in a string.
str.replace(self, needle, val)
Argument | Information |
---|---|
self |
self argument |
needle |
str to be replaced |
val |
str to replace |
"abc".replace("a","b") == "bbc" == True
New string - str
Join an iterator with a string.
str.join(self, iter)
Argument | Information |
---|---|
self |
self argument |
iter |
iterable to be joined |
" ".join([1,2,3]) == "1 2 3 " == True
New string - str
Split a string on string needle
.
str.split(self, needle="")
Argument | Information |
---|---|
self |
self argument |
needle |
needle to split on, defaults to "" |
"abc".split("b") == ["a","c"] == True
New list - list
Return a new string with all characters uppercase.
str.upper(self)
Argument | Information |
---|---|
self |
self argument |
"abc".upper() == "ABC" == True
New string - str
Return a new string with all characters lowercase.
str.lower(self)
Argument | Information |
---|---|
self |
self argument |
"ABC".lower() == "abc" == True
New string - str
Return True
if string is only whitespace, otherwise, False
.
str.isspace(self)
Argument | Information |
---|---|
self |
self argument |
"abc".isspace() == False == True
New boolean - bool
ReturnTrue
if string is only alphabetic characters, otherwise, False
.
str.isalpha(self)
Argument | Information |
---|---|
self |
self argument |
"abc".isalpha() == True == True
New boolean - bool
Returns True
if string is only numbers, otherwise, False
.
str.isnumeric(self)
Argument | Information |
---|---|
self |
self argument |
"123".isnumeric() == True == True
New boolean - bool
Return True
if string is only uppercase characters, otherwise, False
.
str.isupper(self)
Argument | Information |
---|---|
self |
self argument |
"abc".isupper() == False == True
New boolean - bool
Return True
if string is only lowercase characters, otherwise, False
.
str.islower(self)
Argument | Information |
---|---|
self |
self argument |
"abc".islower() == True == True
New boolean - bool
Get count of substring in a string
str.count(self, substr)
Argument | Information |
---|---|
self |
self argument |
substr |
substring |
"abca".count("a") == 2 == True
New int - int
Strips whitespace off a string
str.strip(self)
Argument | Information |
---|---|
self |
self argument |
"12 ".strip() == "12" == True
New string - str
Strips leading whitespace off a string
str.kstrip(self)
Argument | Information |
---|---|
self |
self argument |
"12 ".lstrip() == "12 " == True
New string - str
Strips trailing whitespace off a string
str.strip(self)
Argument | Information |
---|---|
self |
self argument |
"12 ".rstrip() == "12" == True
New string - str
Return True
is needle is found in self
, otherwise, False
str.contains(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
str needle |
"abc".contains("c") == True
Boolean - bool
Encodes self
as encoding encoding
str.encode(self, encoding)
Argument | Information |
---|---|
self |
self argument |
encode |
encoding |
Bytes object containing encoded string - bytes
Return True
if the string starts with needle, otherwise, False
.
str.startswith(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
Boolean - bool
Return True
if the string ends with needle, otherwise, False
.
str.endswith(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
Boolean - bool
Return the last occurence of needle, or -1;
str.rfind(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
Index - int
Find and return index of first occurance of argument needle
, or -1.
list.find(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
[1,2,3].find(2) == 1 == True
Index - int
Replaces all occurances of argument needle
with val
.
list.replace(self, needle, val)
Argument | Information |
---|---|
self |
self argument |
needle |
needle to be replace |
val |
value to replace |
[1,2,3].replace(2,3) == [1,3,3] == True
Same object, altered - list
Appends argument val
to list.
list.append(self, val)
Argument | Information |
---|---|
self |
self argument |
val |
value to append |
[1,2,3].append(4) == [1,2,3,4] == True
None
Pops element at idx from list and returns item.
list.pop(self, idx=-1)
Argument | Information |
---|---|
self |
self argument |
idx |
index to pop from |
[1,2,3].pop() == 3 == True
Popped value
Inserts value into list at specified index
list.insert(self, idx, val)
Argument | Information |
---|---|
self |
self argument |
idx |
index to insert at |
val |
value to insert |
a=[1,2,3]
a.insert(0, "A")
a == ["A",1,2,3] == True
None
Removes first occurrence of value from list
list.remove(self, val)
Argument | Information |
---|---|
self |
self argument |
val |
value to insert |
a=[1,2,3]
a.remove(1)
a == [2,3] == True
None
Extends list by passed iterator
list.extend(self, it)
Argument | Information |
---|---|
self |
self argument |
it |
iterator |
a=[1,2,3]
a.extend({4,5,6})
a == [1,2,3,4,5,6] == True
None
Returns a list of keys.
dict.keys(self)
Argument | Information |
---|---|
self |
self argument |
{1:2}.keys() == [1] == True
List of keys - list
Returns a list of values.
dict.values(self)
Argument | Information |
---|---|
self |
self argument |
{1:2}.values() == [2] == True
List of values - list
Create a new dictionary with the key-value pairs in the original dictionary flipped.
dict.flip(self)
Argument | Information |
---|---|
self |
self argument |
{1:2}.flip() == {2:1} == True
New dict - dict
Find and return index of first occurance of argument needle
, or -1.
tuple.find(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
(1,2,3).find(2) == 1 == True
Index - int
Returns contents of an open, readable file object.
file.read(self)
Argument | Information |
---|---|
self |
self argument |
file("test.txt"),"r".read() == "ABC" == True
Contents of file - str
Closes a file object.
file.close(self)
Argument | Information |
---|---|
self |
self argument |
file("test.txt","r").close() == None == True
None
Seeks to absolute position in an open file object.
file.seek(self, idx)
Argument | Information |
---|---|
self |
self argument |
idx |
absolute index to seek to |
file("test.txt","r").seek(10) == None == True
None
Writes val.__str__()
to open, writeable file object.
file.seek(self, val)
Argument | Information |
---|---|
self |
self argument |
val |
object to write |
file("test.txt", "w").write(123).read() == "123" == True
File object - file
Returns the size of open file object.
file.size(self)
Argument | Information |
---|---|
self |
self argument |
file("test.txt","r").size() == 3 == True
Size - int
Flushes file
file.flush(self)
Argument | Information |
---|---|
self |
self argument |
file("test.txt","w").flush() == None == True
None
Find and return index of first occurance of argument needle
, or -1.
set.find(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
{1,2,2,3}.find(2) == 1 == True
Index - int
Adds item
to set if the item does not exist
set.add(self, item)
Argument | Information |
---|---|
self |
self argument |
item |
item to add |
{1,2,2,3}.add(4) == {1,2,2,3,4} == True
None - None
Tries to remove item
from the set. On failure, raise KeyError
set.remove(self, item)
Argument | Information |
---|---|
self |
self argument |
item |
item to remove |
a={1,2,3}
a.remove(3)
a == {1,2} == True
None - None
Returns the union of set self
and set other
.
set.union(self, item)
Argument | Information |
---|---|
self |
self argument |
other |
other set |
a={1,2,3}
a=a.union({4,})
a == {1,2,3,4} == True
None - None
Decodes self
into a string, interpreting bytes in self
as encoding
bytes.encode(self, encoding)
Argument | Information |
---|---|
self |
self argument |
encode |
encoding |
Decoded string - str
Converts byte object to a hexadecimal string.
bytes.hex(self)
Argument | Information |
---|---|
self |
self argument |
Hexadecimal string - str
Find and return index of first occurance of argument needle
, or -1.
bytearray.find(self, needle)
Argument | Information |
---|---|
self |
self argument |
needle |
needle |
bytearray([1,2,3]).find(2) == 1 == True
Index - int
Replaces all occurances of argument needle
with val
.
bytearray.replace(self, needle, val)
Argument | Information |
---|---|
self |
self argument |
needle |
needle to be replace |
val |
value to replace |
bytearray([1,2,3]).replace(2,3) == bytearray([1,3,3]) == True
Same object, altered - bytearray
Appends argument val
to bytearray.
bytearray.append(self, val)
Argument | Information |
---|---|
self |
self argument |
val |
value to append |
bytearray([1,2,3]).append(4) == bytearray([1,2,3,4]) == True
None
Pops element at idx from bytearray and returns item.
bytearray.pop(self, idx=-1)
Argument | Information |
---|---|
self |
self argument |
idx |
index to pop from |
bytearray([1,2,3]).pop() == 3 == True
Popped value
Inserts value into bytearray at specified index
bytearray.insert(self, idx, val)
Argument | Information |
---|---|
self |
self argument |
idx |
index to insert at |
val |
value to insert |
a=bytearray([1,2,3])
a.insert(0, "A")
a == ["A",1,2,3] == True
None
Removes first occurrence of value from bytearray
bytearray.remove(self, val)
Argument | Information |
---|---|
self |
self argument |
val |
value to insert |
a=bytearray([1,2,3])
a.remove(1)
a == bytearray([2,3]) == True
None
Extends bytearray by passed iterator
bytearray.extend(self, it)
Argument | Information |
---|---|
self |
self argument |
it |
iterator |
a=bytearray([1,2,3])
a.extend({4,5,6})
a == bytearray([1,2,3,4,5,6]) == True
None
Converts bytearray object to a hexadecimal string.
bytearray.hex(self)
Argument | Information |
---|---|
self |
self argument |
Hexadecimal string - str