s=‘alice‘ print(s,type(s),id(s))
打印结果: s <class ‘str‘ 32165416>
打印: 字符串内容,type(s):变量s对应的数据类型,id(s):变量s对应的内存地址
== / is s1=‘alice; s2=‘alice‘ print(s1==s2) true , == 比较的是两个变量的值 print(s1 is s2) true , is 比较的是内存地址,是不是同一个对象
listA = [1,2,3]
listB = [1,2,3]
print(listA == listB) true
print(listA is listB) false
以上 列表 字典 元组,set 类似
函数 计算0到len的和 def getFun(len): int sum= 0 for i in range(0 ,len): sum+=i return sum print(getFun(10))
//默认参数
def showInfo(name,sex=‘男‘):
print(‘姓名:%s,性别:%s‘%(name,sex))
showInfo(‘张三‘)
showInfo(‘王五‘)
showInfo(‘小美‘,‘女‘)
姓名:张三,性别:男
姓名:王五,性别:男
姓名:小美,性别:女
原文:https://www.cnblogs.com/xqxacm/p/9795009.html