Python取值的灵活性用法

samp_string = "Whatever you are, be a good one."

for i in samp_string:
    print(i)
for i in range(0,len(samp_string)-2,2):
    print(samp_string[i]+samp_string[i+1])

print('A=',ord("A"))
print('65=',chr(65))

print('桃:',ord(""))
print('26690',chr(26690))


# # You can get a character by referencing an index
# print(samp_string[0])

print(samp_string[0])
# # Get the last character
print(samp_string[-2])
#
# # Get the string length
print("Length : ", len(samp_string))
#
# # Get a slice by saying where to start and end
# # The 4th index isn't returned
print(samp_string[0:4])
#
# # Get everything starting at an index
print(samp_string[8:])
# print()
#
print(samp_string)
print(samp_string[::])
print(samp_string[::2])
#
# # Reverse the string
print(samp_string[::-1])
# # Palindrome
print('I did, did I?'[::-1])
print('No lemon, no melon'[::-1])
#
# # Practical use
url = "http://pythonabc.org"
# Get the top level domain
print(url[-3:])
# Print the url without the http://
print(url[7:])
# Print the url without the http:// or the top level domain
print(url[7:-4])

 

posted @ 2019-05-22 22:17  木&子  阅读(326)  评论(0编辑  收藏  举报