1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| def main(): str1 = 'hello, world!' print(len(str1)) print(str1.capitalize()) print(str1.upper()) print(str1.find('or')) print(str1.find('shit')) print(str1.startswith('He')) print(str1.startswith('hel')) print(str1.endswith('!')) print(str1.center(50, '*')) print(str1.rjust(50, ' ')) str2 = 'abc123456' print(str2[2]) print(str2[2:5]) print(str2[2:]) print(str2[2::2]) print(str2[::2]) print(str2[::-1]) print(str2[-3:-1]) print(str2.isdigit()) print(str2.isalpha()) print(str2.isalnum()) str3 = ' [email protected] ' print(str3) print(str3.strip())
if __name__ == '__main__': main()
|