随笔分类 - Python基础
有关于python的一些基础知识和一些练习题小程序
摘要:一个记录日志的函数 1 import time 2 def logger(n): 3 time_format = '%Y-%m-%d %X' 4 time_current = time.strftime(time_format) 5 6 with open('日志记录','a') as f: 7 f
阅读全文
摘要:示例 浅拷贝 浅拷贝只会拷贝第一层 深拷贝 关键词dir.deepcopy()
阅读全文
摘要:集合的作用 1.去重 2.关系测试 集合的访问 集合的删除 集合的关系
阅读全文
摘要:作用域 作用范围:built-in>global>enclosing>local 作用范围:global>enclosing>local>built-in L(local)局部作用域 局部变量:包含在def关键字定义的语句块中,即在函数中定义的变量。每当函数被调用时都会创建一个新的局部作用域。Pyt
阅读全文
摘要:文件的最基本读写方式 #注意 如果用这种方式打开的文件 一定要使用close()方法关闭文本 虽然python一般情况下会自动关闭文档 Read的一些方法 Wirte的一些方法 r+ w+ a+ with同时管理多个对象
阅读全文
摘要:字符串的内置用法: 1 st='hello kitty {name} age is {age}' 2 print(st.count('l')) #统计元素个数 3 print(st.capitalize()) #首字母大写 4 print(st.center(50,'-')) #居中 5 print
阅读全文
摘要:还有一些其他用法 元组的创建 1 menu={ 2 '北京':{ 3 '朝阳':{ 4 '国贸':{ 5 'CICC':{}, 6 'HP':{}, 7 '渣打银行':{}, 8 'CCTV':{}, 9 }, 10 '望京':{ 11 '陌陌':{}, 12 '奔驰':{}, 13 '360':{
阅读全文
摘要:1 while True: 2 salary = input("please input your salary:") 3 if salary.isdigit(): 4 salary=int (salary) 5 break 6 else: 7 print("Invalid input! pleas
阅读全文
摘要:1 _user="cindy" 2 _pwd="password" 3 passed_authentication = False 4 for i in range (3): 5 username = input("Username=") 6 password = input("Password="
阅读全文
摘要:1 line =9 2 while line >0: 3 #print ("*") 4 tmp =line 5 while tmp >0: 6 print ("#",end="") 7 tmp-=1 8 line -=1 9 print() 10 11 first =0 12 while first
阅读全文
摘要:列表,元组 查 索引(下标) ,都是从0开始 切片 .count 查某个元素的出现次数 .index 根据内容找其对应的位置 "haidilao ge" in a 增加 a.append() 追加 a.insert(index, "内容") a.extend 扩展 修改 a[index] = "新的
阅读全文

浙公网安备 33010602011771号