switcher ={
:'sunday',
:'monday',
:'thuesday'
} day =
day_name=switcher.get(day,'Unknow')
print(day_name) # sunday
def get_sunday():
return 'sunday' def get_monday():
return 'monday' def get_thuesday():
return 'thuesday' def get_default():
return 'Unknow' switcher ={
:get_sunday,
:get_monday,
:get_thuesday
} day =
day_name=switcher.get(day,get_default)()
print(day_name) # sunday
# 列表推到式
# 集合推到式
# map filter
# set
# dict
a = [,,,,,,,]
# b = [i*i for i in a]
b = [i** for i in a]
print(b) # [, , , , , , , ]
c = [i** for i in a]
print(c) # [, , , , , , , ]
d = [i** for i in a if i > ]
print(d) # [, , ] e =(,,,,,,,)
f = [i** for i in a if i > ]
print(f) # [, , ]
g = {i** for i in a if i > }
print(g) # {, , }
students = {
'喜小乐':,
'石敢当':,
'张三':
}
# 字典
b = {key for key,value in students.items()}
print(b) # {'石敢当', '喜小乐', '张三'}
b = {value for key,value in students.items()}
print(b) # {, , }
b = {value:key for key,value in students.items()}
print(b) # {: '喜小乐', : '石敢当', : '张三'} # 元组
b = (key for key,value in students.items())
for x in b:
print(x)
# 喜小乐
# 石敢当
# 张三
# None 空
# 空字符串 空的列表 False
a = ''
b = False
c =[]
print(a==None) # False
print(b==None) # False
print(c==None) # False
print(a is None) # False
print(type(None)) # <class 'NoneType'> a = []
a =''
a = None # 不存在
a = False # 真假 判断为空的方式
if a:
if not a:
class Test():
def __len__(self):
return
# return
# return True test = Test()
if test:
print('S') # True/
else:
print('F') # print(len(Test())) #
print(bool(Test())) # False
class Test():
def __bool__(self):
return False def __len__(self):
return True test = Test()
if test:
print('S')
else:
print('F') # F

15.Pythonic与python杂记的更多相关文章

  1. Python(十二) Pythonic与Python杂记

    一.导言 二.用字典映射代替switch case语句   # 字典代替 switch 语句 # switch () # { # case 0 : # dayName= 'a'; # break; # ...

  2. Python3(十二) Pythonic与Python杂记

    一.用字典映射代替switch case语句 if/else可以代替switch但是非常不合适. 用字典代替switch: day = 5 switcher = { 0:'Sunday', 1:'Mo ...

  3. Be Pythonic ,Google Python Style Guide

    为了更规范的写代码,变得更专业 分号 1 不在句末添加分号,不用分号在一行写两句代码 行长度 2 每行不超过80字符,python会隐式行连接圆括号,中括号,花括号中的字符,如多参数方法调用可以写为多 ...

  4. python杂记二

    1. 写文件可以直接使用print函数 file_name = open("file_name.txt","w") print("file conta ...

  5. PAT 1031 查验身份证(15)(C++&Python)

    1031 查验身份证(15)(15 分) 一个合法的身份证号码由17位地区.日期编号和顺序编号加1位校验码组成.校验码的计算规则如下: 首先对前17位数字加权求和,权重分配为:{7,9,10,5,8, ...

  6. python 杂记-unittest

    介绍单元测试的好文:https://mp.weixin.qq.com/s/njxc8GXSlc3z_RibK70ROg setUpModule/tearDownModule:在整个模块的开始和结束时被 ...

  7. python杂记-4(迭代器&生成器)

    #!/usr/bin/env python# -*- coding: utf-8 -*-#1.迭代器&生成器#生成器#正确的方法是使用for循环,因为generator也是可迭代对象:g = ...

  8. python杂记-3(购买商品)

    #!/usr/bin/env python# -*- coding: utf-8 -*-#如下是一个购物程序:#先输入工资,显示商品列表,购买,quit退出,最后格式化输出所买的商品.count = ...

  9. python杂记-1(os模块)

    os模块说明:python os模块包含普遍的操作系统功能 os.access(path, mode) # 检验权限模式 os.chdir(path) # 改变当前工作目录os.chflags(pat ...

随机推荐

  1. linux关闭进程

    查看端口对应的pid lsof -i:8888 若要关闭使用这个端口的程序,使用kill + 对应的pid kill -9 PID号

  2. SpringMVC:详述拦截器

    将堆内存SpringMVC使用拦截器对请求进行拦截处理,以实现特定的功能: 具体实现: 1.自定义一个实现HandlerInterceptor接口的类并实现接口中定义的抽象方法(实现了三个方法,分别处 ...

  3. 用Jackson进行Json序列化时的常用注解

    Jackson时spring boot默认使用的json格式化的包,它的几个常用注解: @JsonIgnore 用在属性上面,在序列化和反序列化时都自动忽略掉该属性 @JsonProperty(&qu ...

  4. mybatis+spring boot+vue

    参考https://www.cnblogs.com/wlovet/p/8317282.html

  5. java 并发线程锁

     1.同步和异步的区别和联系 异步,执行完函数或方法后,不必阻塞性地等待返回值或消息,只需要向系统委托一个异步过程,那么当系统接收到返回 值或消息时,系统会自动触发委托的异步过程,从而完成一个完整的流 ...

  6. Python学习第十课——文件的基本操作

    文件基本操作 文件读操作 #读出路径下的测试.txt文件 f = open('测试.txt', encoding='utf-8') # 打开要读文件 data = f.read() # 读取内容 pr ...

  7. 帆软FineReport报表由于使用HTML显示后无法控制行高

    问题:帆软FineReport报表由于使用HTML显示后无法控制行高. 原因:首先每行的第一个单元格是以HTML显示的,然后,数据库查询的数据集中,sql语句中包含这个代码:'<pre>' ...

  8. C++面试常见问题——04链表的逆序与合并

    链表的逆序与合并 链表的逆序 已知一个链表的头指针为head,将该链表逆序. #include<iostream> using namespace std; struct Node{ in ...

  9. 3 (mysql实战) 事务隔离

    提到事务,你肯定不陌生,和数据库打交道的时候,我们总是会用到事务.最经典的例子就是转账,你要给朋友小王转 100 块钱,而此时你的银行卡只有 100 块钱. 转账过程具体到程序里会有一系列的操作,比如 ...

  10. axios发送post请求[body-parser]--['Content-type': 'application/x-www-form-urlencoded']

    const express = require('express') const axios = require('axios') const bodyParser = require('body-p ...