前言:主要是python3字符串、列表、元组编写程序中最常用的用法。

一、容易弄混的逻辑运算符

1.% 取余数   比如 11 % 2  返回的值是1

Python3的数据类型 (字符串、列表、元组)

2.+= 代表的赋值运算符  比如 a +=1 相当于a = a+1

比如:如下例子

Python3的数据类型 (字符串、列表、元组)

3.强制类型转换

Python3的数据类型 (字符串、列表、元组)  可以用来处理取整数的实际需求

二、字符串常用的方法  (部分操作,参考python3菜鸟教程)

1.strip 字符串过滤空格,只能过滤前和尾的空格 (或者是字符)

Python3的数据类型 (字符串、列表、元组)

对特定字符过滤,也只能过滤前跟尾指定的字符

Python3的数据类型 (字符串、列表、元组)

2.replace  替换字符串的内容  replace(old,new)

Python3的数据类型 (字符串、列表、元组)  Python3的数据类型 (字符串、列表、元组)

3.find 查找字符串中子字符串,字符串的内容如果找到,返回字符串的一个下标,没找到返回-1

Python3的数据类型 (字符串、列表、元组) Python3的数据类型 (字符串、列表、元组)

4.format 变量和字符串格式化

Python3的数据类型 (字符串、列表、元组)

5.split 切割字符串

Python3的数据类型 (字符串、列表、元组)Python3的数据类型 (字符串、列表、元组)

6.join合并字符串

Python3的数据类型 (字符串、列表、元组)Python3的数据类型 (字符串、列表、元组)


三、列表的常用方法 list[]

定义:list 一序列特定顺序排列的元素组成,列表中元素下标默认从0开始。

1.append 末尾增加一个元素,没有返回值

Python3的数据类型 (字符串、列表、元组) Python3的数据类型 (字符串、列表、元组)

2.pop 末尾删除一个元素,返回删除的元素

Python3的数据类型 (字符串、列表、元组)Python3的数据类型 (字符串、列表、元组)

3.index 返回该元素的下标

Python3的数据类型 (字符串、列表、元组)Python3的数据类型 (字符串、列表、元组)


3.remove 删除元素

Python3的数据类型 (字符串、列表、元组)Python3的数据类型 (字符串、列表、元组)

4.sort  排序

Python3的数据类型 (字符串、列表、元组)

Python3的数据类型 (字符串、列表、元组)

5.reverse 反序

Python3的数据类型 (字符串、列表、元组)Python3的数据类型 (字符串、列表、元组)

四、元组的常用方法 tuple ()

1.index  找出元素所在元组索引值

Python3的数据类型 (字符串、列表、元组)

Python3的数据类型 (字符串、列表、元组)

2.count  统计某个元素在该元组中出现的次数

Python3的数据类型 (字符串、列表、元组)

Python3的数据类型 (字符串、列表、元组)














相关文章:

  • 2021-11-30
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2021-04-19
  • 2021-10-10
猜你喜欢
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案