python整理面试题(1)
来源:互联网 发布:杭州多赢网络 编辑:程序博客网 时间:2024/06/05 10:19
1. 在1 2 3 4 5 6 7 8 9九个数字中插入“+”或“-”符号使得结果为100
from itertools import productdef total_100(): results,numbers = [],range(1,10) for item in product(['+','-',''],repeat=8): # print(item) number_tuple = zip(numbers,item+("",)) a = [str(x)+y for x,y in number_tuple] combine = "".join(a) if eval(combine) == 100: results.append(combine + "= 100") return resultsnew_lst = total_100()for item in new_lst: print(item)
结果
1+2+3-4+5+6+78+9= 1001+2+34-5+67-8+9= 1001+23-4+5+6+78-9= 1001+23-4+56+7+8+9= 10012+3+4+5-6-7+89= 10012+3-4+5+67+8+9= 10012-3-4+5-6+7+89= 100123+4-5+67-89= 100123+45-67+8-9= 100123-4-5-6-7+8-9= 100123-45-67+89= 100
2.
print(10//3) #3print(10%3) #1print(10.0 % 3)# 3.0
3.
listTemp = [1,2,3]print(listTemp[3]) #报错print(listTemp[3:])# []
4.
if dictTemp: print("result A") elif dictTemp is None: print("result B") else: print("result C")#result C
5.
listA = [[x,x*x]for x in range(10)if x%2] print(listA)#[[1, 1], [3, 9], [5, 25], [7, 49], [9, 81]]
6.
a = 1def change(a): a = 2change(a)print(a) #1
7.
a = [1]def change(a): a.append(2) a = [1]change(a)print(a) #[1,2]
8.
#Python中的对象之间赋值时是按引用传递的,如果需要拷贝对象,需要使用标准库中的copy模块。 #1. copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象。 #2. copy.deepcopy 深拷贝 拷贝对象及其子对象 import copya = [1,2,3,4,['a','b']]b = ac = copy.copy(a)d = copy.deepcopy(a)a.append(5)a[4].append('c')print(a)#[1, 2, 3, 4, ['a', 'b', 'c'], 5]print(b)#[1, 2, 3, 4, ['a', 'b', 'c'], 5]print(c)#[1, 2, 3, 4, ['a', 'b', 'c']]print(d)#[1, 2, 3, 4, ['a', 'b']]
import rea = re.compile("[a-zA-z]{4}")print(re.findall(a,"i Love Python"))
阅读全文
0 0
- python整理面试题(1)
- Python面试题整理
- Python 面试题整理
- python 面试题 - 知识点整理
- python 面试题 - 知识点整理
- python 常见面试题整理
- java面试题收集整理(1)
- Android面试题整理(1)
- Android面试题整理2017(1)
- Android面试题整理(1)
- 常见面试题整理---Python代码篇
- 常见面试题整理--Python概念篇
- Android面试题整理(1)
- C#面试题整理1
- Android面试题整理--1
- Android面试题整理-1
- Android面试题整理-1
- 面试题整理(二)
- robot framework 中对于有滚动条的页面中元素的处理
- 数据结构之 栈的应用
- Selenium学习笔记(webdriver环境搭建)
- STL容器
- Caffe+VS2015环境配置Cmake过程报错—— The C compiler identification is unknown解决方案
- python整理面试题(1)
- 12.贝叶斯正则化,在线学习,误差分析,销蚀分析
- Yii2中nginx的伪静态
- 基于Flume的美团日志收集系统(一)架构和设计
- Java IO总结(一) File文件类
- shiro入门级小程序
- CSS
- ECNU女队模板
- weui+swiper 滑动底部导航栏切换 类似微信切换效果