• 8-1笔记


    sort() 自动排序
    eval 自动改格式
    函数是用来重复使用的
    定义函数是有套路的
    1、首先要会写出裸代码,然后看看那里需要重复使用
    2、接下去将需要重复使用的代码转换成参数,代入到函数中
    def fuctionName([param]):
    执行体
    [return]
    len() 求字符串长度
    时效:
    time end
    time.sleep()睡眠一段时间

    带默认值的参数一定要统一放在最后

    (*args) 可变参数(不定长参数)
    global 声明全局变量
    (lambda x:print(x**2))(100) 匿名函数
    find 从字符串中查找字符所在位置
    # 通过len函数计算字符串的长度
    print(len(str1)) # 13
    # 获得字符串首字母大写的拷贝
    print(str1.capitalize()) # Hello, world!
    # 获得字符串变大写后的拷贝
    print(str1.upper()) # HELLO, WORLD!
    # 从字符串中查找子串所在位置
    print(str1.find('or')) # 8
    print(str1.find('shit')) # -1
    # 与find类似但找不到子串时会引发异常
    # print(str1.index('or'))
    # print(str1.index('shit'))
    # 检查字符串是否以指定的字符串开头
    print(str1.startswith('He')) # False
    print(str1.startswith('hel')) # True
    # 检查字符串是否以指定的字符串结尾
    print(str1.endswith('!')) # True
    # 将字符串以指定的宽度居中并在两侧填充指定的字符
    print(str1.center(50, '*'))
    # 将字符串以指定的宽度靠右放置左侧填充指定的字符 左右填充,各一半
    print(str1.rjust(50, ' '))
    str2 = 'abc123456'
    # 从字符串中取出指定位置的字符(下标运算)
    print(str2[2]) # c
    # 字符串切片(从指定的开始索引到指定的结束索引)
    print(str2[2:5]) # c12
    print(str2[2:]) # c123456
    print(str2[2::2]) # c246
    print(str2[::2]) # ac246
    print(str2[::-1]) # 654321cba
    print(str2[-3:-1]) # 45
    # 检查字符串是否由数字构成
    print(str2.isdigit()) # False
    # 检查字符串是否以字母构成
    print(str2.isalpha()) # False
    # 检查字符串是否以数字和字母构成
    print(str2.isalnum()) # True
    str3 = ' jackfrued@126.com '
    print(str3)
    # 获得字符串修剪左右两侧空格的拷贝
    print(str3.strip())

  • 相关阅读:
    rpm命令参数(转载)
    通过KMS服务器激活windows
    icehouse版本中常用操作命令
    openstack环境搭建常用命令
    openstack 重启服务命令
    python连接mysql数据库报错pymysql连接数据库报错TypeError: __init__() takes 1 positional argument but 5 positional arguments
    Linux下LDAP统一认证解决方案
    windows系统添加IP地址黑名单
    网站防止SQL注入
    Windows服务器修改远程端口号的方法
  • 原文地址:https://www.cnblogs.com/liuyuanzzz/p/11283122.html
Copyright © 2020-2023  润新知