zoukankan      html  css  js  c++  java
  • 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])
  • 相关阅读:
    软件工程基础之二——阅读《软件工程基础》的问题
    软件工程基础之一——个人介绍与计划
    个人介绍
    sudoku
    GitHub地址
    疑问②
    概览提问①
    jsp内置对象
    tomcat的环境变量配置
    构造方法的重载代码
  • 原文地址:https://www.cnblogs.com/lyxcode/p/10908954.html
Copyright © 2011-2022 走看看