January 19 "Basic knowledge of Python3"

Source: Internet
Author: User

2.1 Data types
2.2 String
2.3 List operation

2.1 Data types
# Ptyhon运算符‘‘‘数字运算符: + - * / %关系运算符: a == b  a>b  a<b  a!=b  >=  <=赋值运算符: a = b  +=  -=  *=  /=逻辑运算符: and  or  not‘‘‘## 整型(int)a = 10print(a)## 布尔型(bool)  True(真)  Falle(假)## 浮点型(float): 小数类型a = 1.2345print(a)## 字符串(str)string = ‘abc‘print(string)
2.2 String
string = ‘abcdefg aa bbd  ‘## 字符串操作## find: 查找内容所在字符串位置,顺序从0开始;-1表示查不到print(string.find(‘d‘))# 切片:[起始:结束:步长]print(string[0:])print(string[0:5])print(string[0:5:2])# replace (需要替换字符,替换后字符,替换次数)print(string.replace(‘a‘, ‘A‘))print(string.replace(‘a‘, ‘A‘, 2))# split 分隔符(分隔标志,分隔次数)print(string.split())print(string.split(‘ ‘, 1))# strip 去字符串两端的空白字符print(string.strip())# title 首字母大写print(string.title())
2.3 List operation
# append: 添加元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]lt.append(‘d‘)print(lt)# insert: 指定位置插入指定元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]lt.insert(2, ‘%‘)print(lt)# pop: 按下标弹出元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]print(lt.pop())     # 默认从最后弹起print(lt)lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]print(lt.pop(2))print(lt)# remove: 删除元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]lt.remove(‘a‘)print(lt)# index: 查询指定元素的下标lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]print(lt.index(3))# sort 顺序排序lt = [1, 2, 3]lt.sort()print(lt)# reverse   倒序排序lt = [1, 2, 3]lt.reverse()print(lt)

January 19 "Basic knowledge of Python3"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.