Python

print(2<1 and 4>6 or 3 and 4>5 or 6)
print(3>4 or 4<3 and 1==1)
print(1 < 2 and 3 < 4 or 1>2 )
print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)
print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)
print(0 or 2 and 3 and 4 or 6 and 0 or 3)
print(8 or 3 and 4 or 2 and 0 or 9 and 7)

逻辑运算 () > not > and > or

print("%s已经喜欢了沙河%%2的女生" % name) # 如果字符串中有了占位符. 那么后面的所有的%都是占位. 需要转义
print("wuse很色.喜欢了昌平%5的女生") # 这句话中没有占位符. %还是%

print("第一" in "国家第一名") # True

a = 4
a.bit_length() # 计算整数在内存中占用的二进制码的长度

ord("A") # 65
chr(65) # A

切片特点:
1.顾头不顾尾
2.默认从左往右切
3.步长负数从右往左切

字符串操作:
切记:字符串是不可变的对象,所以任何操作对原字符串不会有任何影响
1.s.upper()
2.s.strip()
3.s.replace()
4.s.split()
5.s.format()
6.s.startswith()
7.s.count() # 出现的次数
8.s.find() # 出现的位置,没出现返回-1 s.index() # 出现的位置,没出现报错
9.len(s)

1. ⼤⼩写转来转去
s.capitalize() # 首字母大写
s.lower()
s.upper()
s.swapcase() # 大小写互换
s.casefold() # 不常用, 转换成⼩写
s.title() # 不常用, 单词首字母大写

2. 切来切去
s.center(8, "*") 不常用, 居中,默认空格填充

s.strip() # 默认去空格
s.lstrip() # 去左空格
s.rstrip() # 去右空格

***** s.replace() # 替换

***** s.split() # 切割
3. 格式化
s.format()

4. 格式化
s.startswith()
s.endswith()

s.count()
s.find() # 出现的位置

s.isalnum()
s.isalpha()

s.isdigit() # 数字,不含小数
s.isdecimal()
s.isnumeric() # 识别中文

len(s)
列表
1. list 列表. 用[]表示. 有索引下标. 切片
2. 增删改查
增加: append(), insert(), extend()
删除: pop(), remove(), del list[], clear()
修改: 索引切片修改
查询: for循环
3. 常用操作:
count()计数
len() 求长度  __len__()
sort() 排序 reverse = True 倒序
reverse() 顺序翻转  [::-1]

转载于:https://www.cnblogs.com/arley520/p/11538185.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值