字典数据类型 >>> mycat = {'size':'fat','color':'gray','disposition':'loud'} >>> myca
列表 一个数组中可以有字符串,也可以有数字 >>> spam = [['cat','bat'],[10,20,30]] >>> spam[1] [10, 20, 30] >>> spam[0] ['cat
Python实现SSH Linux下的ssh登录 root@ubuntu:~# ssh root@192.168.1.88 The authenticity of host '192.168.1.88 (192.168.1.88)' can't be establis
配置文件:config.ini [global] country = China language = zh-CN [custom] home = appblog.cn Python脚本 # -*- coding: utf-8 -*- import ConfigParser import os
在Python语言中,json数据与dict字典以及对象之间的转化,是必不可少的操作。 在Python中自带json库。通过 import json 导入。 在json模块有2个方法, loads():将json数据转化成dict数据 dumps():将dict数据转化成json数据 load(
判断一个变量是否数字(整数、浮点数) >>> isinstance(1, (int, long, float)) True >>> isinstance('a', (int, long, float)) False 判断一个字符串的内容是否表示数字(整数
读取邮件列表 import poplib import email from email.parser import Parser def receive_email_pop3(address, password): # 防止报错: poplib.error_proto: line to
Python中日期时间格式化是非常常见的操作,Python 中能用很多方式处理日期和时间,转换日期时间格式是一个常见的功能。Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间。时间间隔是以秒为单位的浮点小数。每个时间戳都以自从格林威治时间1970年01月01日00
传统的文字表达式 >>> d = {'name':'Joe.Ye', 'age':25, 'gender':'male'} >>> d {'gender':
JSON 函数 使用 JSON 函数需要导入 json 库:import json 函数 描述 json.dumps 将 Python 对象编码成 JSON 字符串 json.loads 将已编码的 JSON 字符串解码为 Python 对象 json.dumps json
in string = 'hello world' if 'world' in string: print 'Exist' else: print 'Not exist' find string = &
Python 2.7及以上版本直接使用format设置千分位分隔符 Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32 Type "help"
Python 的类中,主要会使用的两种变量:类变量与成员变量。类变量是类所有实例化对象共有的,而成员变量是每个实例化对象自身特有的。 # -*- coding: utf-8 -*- class ClassTest(): static_a = 'AppBlog.CN'
大写 把所有字符中的小写字母转换成大写字母 >>> str = "hELLO wOrld!" >>> print (str.upper()) HELLO WORLD! 小写 把所有字符中的大写字母转换成小写字母 >>> str = "
Python遍历字典dict的几种方法: # -*- coding: utf-8 -*- dict = {"apple": "苹果", "banana": "香蕉", "orange": &quo