1. 元组和列表的接收

s1,s2 = [,]
print(s1,s2)
# 执行结果: 1 2
s3,s4 = (,)
print(s3,s4)
# 执行结果: 3 4

2. 变量值的交换

a =
b =
print(a,b) # a,b = b,a # 交换两个变量的值
print(a,b) #

3. float函数

print(float(+))
print(float(-))
#+ 转为 3.0
# -3转为 -3.0

4. 去除嵌套列表

list1 = [, [, ], [, ], [, ], , [, [, [, [, []]]]]]
# 去除多余嵌套的列表,得到[, , , , , ,] def func(lst):
ret = []
for l in lst:
if isinstance(l,list):
for i in func(l): # 在这里开始递归
ret.append(i) # func函数返回值是一个列表
else:
ret.append(l)
return ret ret = func(list1)
print(ret)

5. 打印带颜色

#!/usr/bin/env python3
# _*_ coding:utf- _*_ def inRed(s):
return highlight('') + "%s[31;2m%s%s[0m"%(chr(), s, chr())
def inGreen(s):
return highlight('') + "%s[32;2m%s%s[0m"%(chr(), s, chr())
def inPurple(s):
return highlight('') + "%s[35;2m%s%s[0m"%(chr(), s, chr())
def highlight(s):
return "%s[30;2m%s%s[1m"%(chr(), s, chr()) a = "yjmt_1103_"
lis = a.split("_")[]
print(inRed(lis))
print(inGreen(lis))
print(inPurple(lis))

打印效果:

python小方法 随笔记的更多相关文章

  1. python字符串方法学习笔记

    # 一.字符串大小写转换# 字符串首字符大写print("hello world".capitalize())# 将字符串变为标题print("hello WORLD&q ...

  2. [Python ]小波变化库——Pywalvets 学习笔记

    [Python ]小波变化库——Pywalvets 学习笔记 2017年03月20日 14:04:35 SNII_629 阅读数:24776 标签: python库pywavelets小波变换 更多 ...

  3. Python 魔术方法笔记

    魔术方法总是被__包围, 如__init__ , __len__都是常见的魔术方法,这里主要写一下我遇到的一些魔术方法 setitem 对某个索引值赋值时 即可以进行赋值操作,如 def __seti ...

  4. python中strip()方法学习笔记

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''x ...

  5. 【Python】PYTHON中STRIP()方法学习笔记

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''x ...

  6. python - 常用的小方法

    常用的小方法: bin() oct() hex() chr() ord() dir() id() len() int() str() type() help() range(10)   /  rang ...

  7. Requests:Python HTTP Module学习笔记(一)(转)

    Requests:Python HTTP Module学习笔记(一) 在学习用python写爬虫的时候用到了Requests这个Http网络库,这个库简单好用并且功能强大,完全可以代替python的标 ...

  8. python网络爬虫学习笔记

    python网络爬虫学习笔记 By 钟桓 9月 4 2014 更新日期:9月 4 2014 文章文件夹 1. 介绍: 2. 从简单语句中開始: 3. 传送数据给server 4. HTTP头-描写叙述 ...

  9. Python学习的个人笔记(基础语法)

    Python学习的个人笔记 题外话: 我是一个大二的计算机系的学生,这份python学习个人笔记是趁寒假这一周在慕课网,w3cschool,还有借鉴了一些博客,资料整理出来的,用于自己方便的时候查阅, ...

随机推荐

  1. python3给图片添加水印

    #!/usr/local/bin/python3 #coding=gbk import os, io, sys, re, time, json, random from PIL import Imag ...

  2. java程序设计第二课

    抽象基类和接口 能够使用keywordabstact来创建抽象类,该抽象类不能被实例化 也能够使用keywordabstact来描写叙述一个尚未被详细实现的方法,该方法不能包括方法体 一个抽象方法仅仅 ...

  3. wpf Storyboard 不存在可解析名称“ ”的适用名称领域 No applicable name scope exists to resolve the name

    原文:wpf Storyboard 不存在可解析名称“ ”的适用名称领域 No applicable name scope exists to resolve the name 写了一个 Storyb ...

  4. [WPF疑难]ErrorTemplate显示与隐藏问题

    原文:[WPF疑难]ErrorTemplate显示与隐藏问题 [WPF疑难]ErrorTemplate显示与隐藏问题                                         周 ...

  5. QuickReport的OnNeedData的触发情况

    1.设置QuickReport的DataSet为空.2.在QuickReport的BeforePrint里面将要显示的数据集合初始化,如Query1.First;3.在OnNeedData里面写代码, ...

  6. C#基于用户和角色的验证,服务端web 客户端wpf

    应用程序服务 <?xml version="1.0"?> <!--  For more information on how to configure your ...

  7. 探究操作系统的内存分配(malloc)对齐策略

    问题: 我们在写程序的时候经常发现程序使用的内存往往比我们申请的多,为了优化程序的内存占用,搅尽脑汁想要优化内存占用,可是发现自己的代码也无从优化了,怎么办?现在我们把我们的焦点放到malloc上,毕 ...

  8. MessageBox用法大全

    //1.显示提示信息 MessageBox.Show("Hello World!"); //2.给消息框加上标题 MessageBox.Show("Hello World ...

  9. memcached对中文key的支持问题

    默认的memcached客户端对非ANSI的key存取时会有问题,有2种方式解决: 1 在get和set前将缓存的key进行UrlEncode 2 修改memcached.config文件 <e ...

  10. Android零基础入门第36节:Android系统事件的响应

    原文:Android零基础入门第36节:Android系统事件的响应 在开发Android应用时,有时候可能需要让应用程序随系统设置而进行调整,比如判断系统的屏幕方向.判断系统方向的方向导航设备等.除 ...