python中index.slice与slice assignment用法 一.index与slice的定义: index用于枚举list中的元素(Indexes enumerate the elements): slice用于枚举list中元素集合(Slices enumerate the spaces between the elements). slice assignment,是一个语法糖,主要用于list的快速插入.替换.删除元素. 二.语法 index index语法很简单,如下表所…
一.三目(元)运算符 定义:就是 if...else...语法糖前提:简化if...else...结构,且两个分支有且只有一条语句注:三元运算符的结果不一定要与条件直接性关系 cmd = input('cmd: ') print('可以转化为数字') if cmd.isdigit() else print('不可以转化为数字') a = 20 b = 30 res = a if a > b else b # 求大值 print(res) res = 'b为小值' if a >…