1. 面向对象格式
class onesection:
name = '123'
key = None
value = None
def fail_in_the_blank():
logger.info('123')
t1 = onesection()
t1.name = '234'
2. dictionary
d.clear() #清空
d.keys() #返回list
d.values() #返回list
d.items() #返回list
3. 二维数组
nums_battery_weight = [[None] * 3] * 3 #申请三组内存空间一样的,一组三个None的数组
nums_battery_weight = [[] * 3] * 3 #申请三组内存空间一样的,一组三个None的数组
nums_battery_weight = [[None] * 3 , [None] * 3 , [None] * 3] #申请三组内存空间不同的,一组三个None的数组
4. 日志模块
import logging
logger.basicConfig(level=logging.INFO)
logger = logger.getLogger(__name__)
logger.info('print logger')
logger.debug('not show')
5.字符串处理
str.lstrip() #去除左边
str.rstrip() #去除右边
str.strip() #去除两边
#string与list互转
str_list = [
str1,
str2,
str3
]
str_all = ''.join(str_list)
str = 'abcde'
list_str = list(str)
list
['a','b','c','d','e']
6. 字符串转数字
str_int = '123'
str_float = '1.23'
num_int = int(str_int)
num_float = float(str_float)
网友评论