My QA Projects

QA Projects I was involded.

View on GitHub

String Methods

Comparison Methods

s.startswith(substr)
# check if s starts with substr (as an argument)

s.endswith(substr)
# check if s ends with substr

Comparison Methods Example

s = "UC Berkeley"
print(s.startswith("UC"))
print(s.endswith("LEY"))
# Output
True
False

Search Methods

s.index(substr)
# return the index of substr in s, valueError when not found
s.count(substr)
# return the number of times substr appears in s

Search Methods Examples

s = "UC Berkeley"
print(s.index("Berkeley"))
print(s.index("a"))
# Output
3
ValueError: substring not found

# orrurrences of the substring e
print(s.count("e"))
# Output
3

Replacement Method

s.replace(old,new)
print(s.replace("UC", "University of California, "))
# Output
University of California, Berkeley

Strip Method

s.strip()

Strip Method Example

s = " UC Berkeley    \n"
print("*" + s + "*")
print("*" + s.strip() + "*")
# Output
* UC Berkeley
* 
*UC Berkeley*

Validation Methods

s.isalnum()
# check if a s is all aphanumeric

s.isalpha()
# check if a s is all aphabetic

s.isdigit()
# check if a s is all numeric

s.isspace()
# check if a s is all white spaces

Validation Methods Examples

s = "UC"
print(s.isalpha())
# Output
True

s.isalnum()
# Output
True

s.isdigit()
# Output
True

s.isspace()
# Output
True

Case Validation Method

s.isupper()
# check if a s is all uppercase
s.islower()
# check if a s is all lowercase

s = "UC"
print(s.isupper())
# Output
True

Case Conversion Methods

s.upper()
# returns s in all uppercase
s.lower()
# returns s in all lowercase
s.capitalized()
# returns s in capitalized format

Case Conversion Method

print("UC Berkeley".upper())
print("UC Berkeley".lower())
print("UC Berkeley".capitalized())
# Output
UC BERKELEY
uc berkeley
Uc berkeley