zoukankan      html  css  js  c++  java
  • 补充:第9天python的学习字符串

    字符串灰魔法:索引  切片   (for   in循环)中break 和contiune也是适用    len    range

    #索引,下标,获取字符串中的某一个字符
    test1="laonanhai"
    # v=test1[1]
    # print(v)

    #切片
    #test1=“laonanhai”
    # v=test1[0:-1]#表示起值是大于等于0小于最后一位(不包括最后一位-1)
    # print(v)

    #len
    #len python3汉子也是1个字符,python2.7一个汉子3个字符
    test2="老男孩"
    v1=len(test1)
    v2=len(test2)
    print(v1,v2)

    for 变量名 in 字符串
    test="老男孩最牛B"
    count=0
    while count<len(test):
    v=test[count]
    print(v)
    count+=1
    #for 变量名 in 字符串
    for test1 in test:
    print(test1)

        range创建连续或是等间隔的数字

    #v=range(0,100)#帮忙创建连续的数字0 1 2 3等等
    v=range(0,100,5)#帮忙创建间隔5的数字,0 5 10等等
    for test in v:
    print(test)
    #字符串一旦创建就不能修改,或是拼接,都是只能重新生成字符串
    name="laonanhai"
    age=20
    info=name+age
    print(info)

    #将对应索引取出来
    # test=input(">>>>>>")
    # print(test)
    # l=len(test)
    # v=range(0,l)
    # print(l)
    # for item in v:
    # print(item,test[item])


    test=input(">>>>>>")
    for item in range(0,len(test)):
    print(item,test[item])


  • 相关阅读:
    python用于web题里写解密脚本
    改变checkbox和radio的默认样式
    div内元素垂直居中
    icheck.js插件
    glyphicons字形图标
    没有内容的span元素下掉问题
    临界区保护
    信号量的使用&生产者消费者问题
    空闲线程和钩子函数
    线程的时间片轮询调度
  • 原文地址:https://www.cnblogs.com/jianchixuexu/p/11440856.html
Copyright © 2011-2022 走看看