美文网首页
高级数据类型公共方法

高级数据类型公共方法

作者: 4e8ea348373f | 来源:发表于2018-11-25 11:06 被阅读0次

新博客网站1

新博客网站2

# -*- coding:utf-8 -*-

#容器数据类型公共方法

#del(a[1]) == del a[1] 兼容其它语言

#1. python 内置函数

#1.len(str)

#注意 针对dict 之会比较key,不会比较value
#2. max(str)
#3. min(str)

#4. cmp("1","2") 3.0取消,如果要比较字符串大小用比较运算符,dict不可以,list和tulpe都可以
print("1" > "2")

#5.切片(列表元组都可以,dict不可以)
str1 = "fdsfsdf"
list1 = [1,2,3,4]
print(str1[::-2])
print(list1[::-2])

#6. 运算符 字符串,列表,元组支持,dict不可以用*(因为key唯一),+号会生成一个新的变量,extend等作用对象为直接修改此对象
print(list1*5) #[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]
print("fds"+"fsd")
print(list1+[3,6]) #[1, 2, 3, 4, 3, 6]

#7. in 和 not in 包含和不包含 针对字符串(sub 子串),列表,元组,dict(key) 成员运算符

print("ab" in "abcd")
print("ab" in "abcd")

#8.完整for循环可以用else 当list所有的都遍历后,就会执行 else 语句,如果循环被中断,则不会执行

for i in [1,2,3,4,5]:
    print(i)
    if i == 2:
        break
else:
    print("22")

#9. 完整for循环应用场景
find_name = "傻逼1"

students = [
    {"name":"阿泰",
     "age":50},
    {"name":"傻逼",
     "age":100}
]

for student in students:
    print(student)
    if student["name"] == find_name:
        print("位置为:%d" % students.index(student))
        break
else:
    print("没有%s用户" % find_name)

相关文章

  • 14 高级变量类型

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数...

  • 07.Python集合与字符串

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数...

  • 8.Python集合与字符串

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数...

  • 07.Python集合与字符串

    高级变量类型 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数...

  • 高级数据类型公共方法

    新博客网站1新博客网站2

  • Python高级变量类型

    仅用学习参考 目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数...

  • python 高级变量类型

    目标 列表 元组 字典 字符串 公共方法 变量高级 知识点回顾 Python 中数据类型可以分为 数字型 和 非数...

  • JS高级函数

    高级函数 在 JavaScript 中使用函数的高级方法。 数据类型的安全检测 构造函数的安全作用域 惰性载入函数...

  • Day2 Python 基础

    常见数据类型的公共方法 python包含以下常见内置函数 索引和切片 运算符 各数据类型独有的函数 1.字符串的常...

  • 二继承与多态——第三节、接口

    接口就是多个类的公共规范接口是引用数据类型最重要的内容是其中的抽象方法定义接口public interface 接...

网友评论

      本文标题:高级数据类型公共方法

      本文链接:https://www.haomeiwen.com/subject/ujfpqqtx.html