标签:other 命名 ble name ade absolute 括号 定义 code
1 >>>import os 2 >>>os.environ #获取所有环境变量 3 >>>os.environ.get(“dade”) #获取环境变量”dade”的值
用中括号取值和get方法取值的区别 ,get方法获取不到key的时候不会报错,中括号取值找不到key会报错,所以get方法更常用。get方法还可以多传一个参数,如果get不到key的话,那么返回这个参数值。如果不写的话,默认get不到返回None。
assertEqual(self, excepted, observed, message=’’)
excepted:期望值;observed:实际值;如果excepted和observed相等,则通过;msg为失败时打印的信息
1. 基本用法:
1 >>> print "wr are the {} who say {}!".format("knights","Ni") 2 wr are the knights who say Ni!
2. 大括号和其中的字符会被替换成传入 str.format() 的参数。大括号中的数值指明对象中的哪一个:
1 >>> print "{0} and {1}".format(‘span‘,‘eggs‘) 2 span and eggs 3 >>> 4 >>> print "{1} and {0}".format(‘span‘,‘eggs‘) 5 eggs and span
3. 也可以通过参数名来引用值:
1 >>> print "This {food} is {adjective}.".format(food="spam",adjective="absolutely horrible") 2 This spam is absolutely horrible.
4. 位置参数和关键字参数可以随意组合:
1 >>> print "The story of {0}, {1}, and {other}.".format("Bill","Manfred",other="Georg") 2 The story of Bill, Manfred, and Georg.
标签:other 命名 ble name ade absolute 括号 定义 code
原文地址:https://www.cnblogs.com/sunshine-blog/p/9497473.html