美文网首页
Python | 公共方法与总结

Python | 公共方法与总结

作者: Ricsy | 来源:发表于2019-10-01 00:09 被阅读0次


一、总结

不可变的数据类型 可变的数据类型
int、float、bool、str、元组 列表、字典

二、公共方法

运算符 Python表达式 结果 描述 支持的数据类型
+ [1, 2]+[3, 4] [1, 2, 3, 4] 合并 字符串、列表、元组
* ['Hi']*4 ['Hi', 'Hi', 'Hi', 'Hi'] 复制 字符串、列表、元组
in 3 in (1, 2, 3) True 元素是否存在 字符串、列表、元组、字典
not in 4 not in (1, 2, 3) True 元素是否不存在 字符串、列表、元组、字典

2. 1 +

注意顺序、类型的统一

eg:

  • 列表
my_list1 = [1, 2]
my_list2 = [3, 4]
my_list = my_list1+my_list2
print(my_list)

结果:[1, 2, 3, 4]

  • 字符串
name = "小明"
res = "我叫"+name
print(res)

结果:我叫小明

  • 元组
res = (1, 4) + (6, 9)
print(res)

结果:(1, 4, 6, 9)

2.2 *

  • 字符串
my_str = '='
res = my_str*40
print(res)

结果:========================================

  • 列表
my_list = ['hello']*5
print(my_list)

结果:['hello', 'hello', 'hello', 'hello', 'hello']

print(my_list)

结果:['hello', 'world', 'hello', 'world']

  • 元组
my_tuple = (11,)*5
print(my_tuple)

结果:(11, 11, 11, 11, 11)


更新中......


相关文章

  • Python | 公共方法与总结

    一、总结 二、公共方法 2. 1 + 注意顺序、类型的统一 eg: 列表 结果:[1, 2, 3, 4] 字符串 ...

  • 十,容器类型的公共方法

    python容器类型的公共方法 公共方法[图片上传失败...(image-6cd98-1555236575369)...

  • python公共方法

    Python 内置函数 Python 包含了以下内置函数: 注意 字符串 比较符合以下规则: "0" < "A" ...

  • python公共方法

  • Python学习

    第八天 今天简单总结一下Python中公共的运算符以及方法。 1、公共操作-运算符 运算符描述支持类型+合并字符串...

  • 2017.6.13-14

    学习python总结python常用的方法string的常用方法dictionary的常用方法 python抽象,...

  • Python基础知识10: 容器类型公共方法

    一、公共方法的理解所谓公共方法就是:列表,元组,字典,字符串 都可以使用的方法 二、Python 内置函数函数描述...

  • Python中公共方法

    1.内置函数 Python中包含以下内置函数 注意:字符串比较符合以下规则: 0

  • Python基础--公共方法

    公共方法:字符串、列表、元组、字典等都可以使用的方法就叫公共方法 1.运算符的公共方法中有 +、*、比较、判断等,...

  • Python OS模块常用方法总结

    Python OS模块常用方法总结Python OS模块方法:操作 说明os.g...

网友评论

      本文标题:Python | 公共方法与总结

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