首页 > 编程语言 > 详细

Python取值的灵活性用法

时间:2019-05-22 22:27:36      阅读:110      评论:0      收藏:0      [点我收藏+]
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])

 

Python取值的灵活性用法

原文:https://www.cnblogs.com/lyxcode/p/10908954.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!