随笔分类 - Python
python换行写入文件
摘要:#!/usr/bin/env python#ecoding=utf-8 f=open(r"D:\opsdev\olduser\oldused.txt","a+") newline=raw_input('input a string:')f.writelines(newline+"\n") f.clo
阅读全文
python输入字符串
摘要:#!/usr/bin/env python#ecoding=utf-8'''Created on 2017年11月2日题目:利用递归函数调用方式,将所输入的5个字符,以相反顺序打印出来。 @author: James zhan''' def output(s,l): if l==0: return
阅读全文
python输入整数
摘要:#!/usr/bin/env python#ecoding=utf-8'''Created on 2017年11月2日 @author: James zhan''' def fun(n): if n==1 or n==0: return 1 else: return fun(n-1)*ns = in
阅读全文
生成器yield
摘要:#!/usr/bin/python#coding=utf-8'''Created on 2017年11月23日 from home @author: James zhan ''' def counter(start_at=0): count=start_at while True: val=(yie
阅读全文
递归函数
摘要:#!/usr/bin/python#coding=utf-8'''Created on 2017年11月2日 from homeN!=fun(n)=1*2*3 ... * n@author: James zhan ''' def fun(n): if n==0 or n==1: return 1 e
阅读全文
Python第一个GUI
摘要:#!/usr/bin/python#coding=utf-8'''Created on 2017年11月2日 from home @author: James zhan ''' from functools import partialimport Tkinter root=Tkinter.Tk()
阅读全文
内建函数之:reduce()使用
摘要:#!/usr/bin/python#coding=utf-8'''Created on 2017年11月2日 from home @author: James zhan ''' print reduce(lambda x,y:x+y,range(5)) '''reduce函数运行操作步骤((((0+
阅读全文
Python connect mariadb(Python连接mysql)
摘要:#!/usr/bin/python#coding=utf-8 import MySQLdb # 打开数据库连接db = MySQLdb.connect("192.168.1.250","root","123456","mydb" ) # 使用cursor()方法获取操作游标 cursor = db.
阅读全文
Python第一发:Hello world
摘要:#!/usr/bin/pythondef main () : print 'hello world'main ()
阅读全文
浙公网安备 33010602011771号