随笔分类 - python
摘要:读取文件,最常见的方式是: 但是,当完成这一操作时,readlines() 方法(read() 也一样)会将整个文件加载到内存中。在文件较大时,往往会引发 MemoryError(内存溢出)。 那么,如何避免这个问题?
阅读全文
摘要:两个特殊的符号'^'和'$'。他们的作用是分别指出一个字符串的开始和结束。例子如下: "^The":表示所有以"The"开始的字符串("There","The cat"等); "of despair$":表示所以以"of despair"结尾的字符串; "^abc$":表示开始和结尾都是"abc"的
阅读全文
摘要:mysql> ALTER USER 'gao'@'%' IDENTIFIED WITH mysql_native_password BY '123456'; 修改用户密码
阅读全文
摘要:>>>cur.execute("update users set username=%s where id=2",("mypython")) >>>cur.execute("select * from users where id=2") >>>cur.fetchone() >>>conn.comm
阅读全文
摘要:>>>cur.execute("select * from 表名") >>>lines=cur.fetchall() >>>for line in lines: print(line) >>>cur.scroll(1) 游标上移一个位置
阅读全文
摘要:1、cmd pip3 install PyMySQL2、>>>import pymysql3、mysql>create database bookdb character set utf8;4、>>>conn=pymysql.connect(host='localhost',port=3306,us
阅读全文
摘要:print('我考了%d分'%20) msg=''' ---------info of %s----------- name: %s age: %d #字符串不能放到%d处 job: %s salary: %f you will be retired in %s years #数字可以放到%s处 ---------end----------...
阅读全文
摘要:>>> f=open("E:/pythonLearn/140.txt") >>> f.seek(8) #如果文件里是汉字的话,这地方seek括号里面只能是偶数,因为奇数的话就相当把汉字拆分成两半了。 >>> f.readline()
阅读全文
摘要:>>> f=open("E:/pythonLearn/140.txt") >>> for line in f.readlines(): print(line) #在此连续点两次回车即可
阅读全文
摘要:#输出99乘法表 for i in range(1,10): for j in range(1,i+1): print(str(j)+'*'+str(i),end=' ') if j==i: print('\n',end='') #输出指定长、宽的长方形 c=input('请输入长:') k=input('请输入宽:') i...
阅读全文
摘要:#猜数字 import random num_rd=random.randint(0,100) count=1 while 1100): print('数字超出范围了,重新输入') elif num<num_rd: print('猜小了') else: print('猜大了') eli...
阅读全文
摘要:在接收raw_input方法后,判断接收到的字符串是否为数字 例如: str = raw_input("please input the number:") if str.isdigit(): 为True表示输入的所有字符都是数字,否则,不是全部为数字 str为字符串str.isalnum() 所有
阅读全文
摘要:>>> student={"100":"zhansan","aihao":["football","music"]}>>> student{'100': 'zhansan', 'aihao': ['football', 'music']}>>> student_copy=student.copy()
阅读全文
摘要:a="i like {0:10} and {1:>10} end".format("python","java") b="i like {0:10} and {1:^10} end".format("python","java") c="i like {0:^10} and {1:^10} end"
阅读全文
摘要:>>> s=" 333 ">>> s.strip()'333'>>> s=" 555 ">>> s.lstrip()'555 '>>> s.rstrip()' 555'>>> s=" 5,9, ">>> s.rstrip(",")' 5,9, '>>> a="abc">>>
阅读全文
摘要:原来是文档后缀名是.txt造成的,应该改成.py,疏忽了。。。
阅读全文

浙公网安备 33010602011771号