0% found this document useful (0 votes)
8 views2 pages

Python Functions With Examples

The document outlines common functions in Python, categorized into string, numeric, conversion, and character functions, along with their equivalents and examples. It includes functions such as slicing strings, converting data types, and manipulating character values. Each function is demonstrated with a code example for clarity.

Uploaded by

Pride Nkala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Python Functions With Examples

The document outlines common functions in Python, categorized into string, numeric, conversion, and character functions, along with their equivalents and examples. It includes functions such as slicing strings, converting data types, and manipulating character values. Each function is demonstrated with a code example for clarity.

Uploaded by

Pride Nkala
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like