博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
02布尔表达式/条件判断
阅读量:2049 次
发布时间:2019-04-28

本文共 1759 字,大约阅读时间需要 5 分钟。

布尔表达式有and or not 组合时,优先级为:not>and>or,当然可以通过加括号来改变优先级,一般为了不引起歧义,开发过程也应该加上括号

深拷贝、浅拷贝:

list3 = [1,2,3,4,5,[6,7,8]]list3_new = list3#直接等的方式是赋值,相当于创建快捷方式,给列表取了别名,不生成新的对象print(id(list3),id(list3_new))list3[2]=9999print(id(list3),id(list3_new))print(list3_new)输出33864328 3386432833864328 33864328[1, 2, 9999, 4, 5, [6, 7, 8]]浅拷贝:import copylist3 = [1,2,3,4,5,[6,7,8]]list3_new = copy.copy(list3)#浅拷贝生成了新的对象print(id(list3),id(list3_new))list3[2]= 999print(id(list3),id(list3_new))print(list3)print(list3_new)输出:36709256 3671053636709256 36710536[1, 2, 999, 4, 5, [6, 7, 8]][1, 2, 3, 4, 5, [6, 7, 8]]import copylist3 = [1,2,3,4,5,[6,7,8]]list3_new = copy.copy(list3)#浅拷贝生成了新的对象,但是其中的子列表仍然是同一个对象print(id(list3),id(list3_new))list3[5][0] = 999print(id(list3),id(list3_new))print(list3)print(list3_new)输出34415496 3441677634415496 34416776[1, 2, 3, 4, 5, [999, 7, 8]][1, 2, 3, 4, 5, [999, 7, 8]]深拷贝:import copylist3 = [1,2,3,4,5,[6,7,8]]list3_new = copy.deepcopy(list3)#深拷贝列表和子列表都生成了新的对象print(id(list3),id(list3_new))list3[2]= 999print(id(list3),id(list3_new))print(list3)print(list3_new)输出40969096 4097037640969096 40970376[1, 2, 999, 4, 5, [6, 7, 8]][1, 2, 3, 4, 5, [6, 7, 8]]import copylist3 = [1,2,3,4,5,[6,7,8]]list3_new = copy.deepcopy(list3)print(id(list3),id(list3_new))list3[5][0]= 999print(id(list3),id(list3_new))print(list3)print(list3_new)输出40641416 4064269640641416 40642696[1, 2, 3, 4, 5, [999, 7, 8]][1, 2, 3, 4, 5, [6, 7, 8]]

条件判断:

1、Python对于缩进是有严格要求的,但是对于缩进几个字符是没有强制性要求的。
2、几个判断字符串的方法:
str1 = ‘21341afd’
str1.isdigit(),str1.isalpha(),str1.isupper(),str1.islower(),str1.isalnum()【是否数字字母组合】

a = '123kdi1D'print(a.isalnum())print(a.islower())print(a.isupper())print(a.isdigit())b = a.upper()print(b)c = a.lower()print(c)输出TrueFalseFalseFalse123KDI1D123kdi1d

转载地址:http://echof.baihongyu.com/

你可能感兴趣的文章
Java Guava中的函数式编程讲解
查看>>
Eclipse Memory Analyzer 使用技巧
查看>>
tomcat连接超时
查看>>
谈谈编程思想
查看>>
iOS MapKit导航及地理转码辅助类
查看>>
检测iOS的网络可用性并打开网络设置
查看>>
简单封装FMDB操作sqlite的模板
查看>>
iOS开发中Instruments的用法
查看>>
iOS常用宏定义
查看>>
被废弃的dispatch_get_current_queue
查看>>
什么是ActiveRecord
查看>>
有道词典for mac在Mac OS X 10.9不能取词
查看>>
关于“团队建设”的反思
查看>>
利用jekyll在github中搭建博客
查看>>
Windows7中IIS简单安装与配置(详细图解)
查看>>
linux基本命令
查看>>
BlockQueue 生产消费 不需要判断阻塞唤醒条件
查看>>
ExecutorService 线程池 newFixedThreadPool newSingleThreadExecutor newCachedThreadPool
查看>>
强引用 软引用 弱引用 虚引用
查看>>
数据类型 java转换
查看>>