My QA Projects

QA Projects I was involded.

View on GitHub

String Methods

Building Strings

str(object)
# return a string from a given object
mean = (1+2+3+4) / 4
print('the aver is: ' + mean + '.')
# Output 
Typeerror: can only concatenate str (not float) to str

print('the aver is: ' + str(mean) + '.')
# Output 
the aver is: 2.5.

Formatted String Literals

mean = (1+2+3+4) / 4
print(f'the aver is: {mean}.')

Format specifiers

,.2f

# , thousands seperator
# .2f two digits after the decimal point
price = 12345.6
print(f'the price is: {price}.')
print(f'the price is: {price:,.2f}.')

Floating point

pi = 3.14159
print(f'pi with 3 digits: {pi:,.3f}.')x 

Alignment and Width

city = 'Berkeley'
print(f'|{city:<20}|')
print(f'|{city:^20}|')
print(f'|{city:>20}|')

# Output
|Berkeley           |
|       Berkeley    |
|           Berkeley|