Common Functions in Python (With Examples)
String Functions
LEFT → Python equivalent: s[:x]
Example:
s = "ABCDEFGH"
print(s[:3]) # ABC
RIGHT → Python equivalent: s[-x:]
Example:
s = "ABCDEFGH"
print(s[-3:]) # FGH
MID → Python equivalent: s[x-1:x-1+y]
Example:
s = "ABCDEFGH"
print(s[1:4]) # BCD
LENGTH → Python equivalent: len(s)
Example:
print(len("Happy Days")) # 10
TO_UPPER → Python equivalent: [Link]()
Example:
print("Error 803".upper())
TO_LOWER → Python equivalent: [Link]()
Example:
print("JIM 803".lower())
Numeric Functions
INT → Python equivalent: int(x)
Example:
print(int(27.5415)) # 27
RAND → Python equivalent: [Link](0, x)
Example:
import random
print([Link](0, 87))
Conversion Functions
NUM_TO_STR → Python equivalent: str(x)
Example:
print(str(87.5))
STR_TO_NUM → Python equivalent: int()/float()
Example:
print(float("23.45"))
IS_NUM → Python equivalent: try/except
Example:
s = "-12.36"
try:
float(s)
print(True)
except:
print(False)
Character Functions
ASC → Python equivalent: ord(char)
Example:
print(ord("A")) # 65
CHR → Python equivalent: chr(x)
Example:
print(chr(65)) # A