zoukankan      html  css  js  c++  java
  • 数据类型之字符串

    姓名 性别 住址等描述性信息的数据 

    定义方式:‘’ “”

    按索引取值

    print(msg[0],type[0])

    print(msg[-1])

    切片:

    切片(顾头不顾尾,步长)

    print(msg[0:3]) #>=0 <3
    print(msg[0:7]) #>=0 <7
    print(msg[0:7:1]) #>=0 <7
    print(msg[0:7:2]) #hello w #hlow
    print(msg[:])
    print(msg[5:1:-1])

    print(msg[-1::-1])

    长度len
     print(msg.__len__())
     print(len(msg)) #msg.__len__()

    成员运算in和not in
     msg='hello world'
     print('llo' in msg)
     print('llo' not in msg)

    移除空白strip
     password=' alex3714 '
     print(password.strip())

     password=input('>>: ').strip()

     password='alex 3714 '
     print(password.strip())

    切分split
     user_info='root:x:0:0::/root:/bin/bash'
     res=user_info.split(':')
     print(res[0])

     cmd='get /root/a/b/c/d.txt'
     print(cmd.split())

     file_path='C:\a\d.txt'
     print(file_path.split('\',1))

     file_path='C:\a\d.txt'
     print(file_path.rsplit('\',1))

    循环
    msg='hel'

     n=0
     size=len(msg)
     while n < size:
     print(msg[n])
     n+=1

     for i in msg: #i=l
     print(i)

     for i in range(0,5,2): #0 2 4
     print(i)

     msg='hel'
     for i in range(len(msg)): #0 1 2
     print(msg[i])

     for i in range(3):
     print(i)

     x='aaa'
     print(id(x))
     x='bbb'
     print(id(x))

  • 相关阅读:
    LeetCode:33. Search in Rotated Sorted Array
    重拾 ACM-HDU 2000-2009
    hdu 1022 数据结构 stack模拟
    画椭圆
    声控灯
    VC++调用R语言
    Setup Factory打包时注册com dll
    折腾树莓派的一些总结
    老调重弹
    制作cpprefernce.chm
  • 原文地址:https://www.cnblogs.com/liqui/p/8040480.html
Copyright © 2011-2022 走看看