zd = "There are 123 apples"
alphas = 0
digits = 0
spaces = 0
for i in zd:
if i.isalpha():
alphas += 1
if i.isdigit():
digits += 1
if i.isspace():
spaces += 1
print 30*"-="
if i.isalpha():
alphas += 1
if i.isdigit():
digits += 1
if i.isspace():
spaces += 1
print 30*"-="
#marked string after we change it by separate string in quote
print("original string is: \"{}\"".format(zd))
print("original string is: \"{}\"".format(zd))
print("there are {} characters".format(len(zd)))
print("there are {} alphas characters".format(alphas))
print("there are {} digits ".format(digits))
print("there are {} spaces.".format(spaces))
output:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
original string is: "There are 123 apples"
there are 20 characters
there are 14 alphas characters
there are 3 digits
there are 3 dpaces.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
string formatting
height: 189.50 cm
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
hex: 12c
0x12c
100101100
454
3.000000e+05
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Brak komentarzy:
Prześlij komentarz