![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
傲世阿龍
这个作者很懒,什么都没留下…
展开
-
python第23篇之--列表操作
#!/usr/bin/pythonshoplist = ['apple','mango','carrot','banana']name = 'swaroop'print('Item 0 is',shoplist[0])print('Item 1 is',shoplist[1])print('Item 2 is',shoplist[2])print('Item 3 is',shopl原创 2017-06-16 09:23:09 · 212 阅读 · 0 评论 -
python第15篇之可变参数的函数的使用
#!/usr/bin/pythondef total(initial=5,*number,**keywords): count = initial for numbers in number: count += numbers for key in keywords: count += keywords[key] prin原创 2017-06-13 11:35:40 · 302 阅读 · 0 评论 -
python第16篇之关键参数赋值(keyword)
#!/usr/bin/pythondef total(initial=5,*numbers,vegetables): count = initial for number in numbers: count += number count += vegetables return countprint(total(10,1,2,3,vegeta原创 2017-06-13 11:44:11 · 696 阅读 · 0 评论 -
python第17篇之-sys模块使用举例
#!/usr/bin/python#filename using_sys.pyimport sysprint('The command line arguments are:')for i in sys.argv: print(i)print('\n\nThe PYTHONPATH is',sys.path,'\n')结果:~/Note/python原创 2017-06-13 11:50:02 · 349 阅读 · 0 评论 -
python第18篇自己构造一个模块使用
构造模块:#!/usr/bin/pythondef sayhi(): print('Hi,this is mymodule speaking')__version__='0.1'模块引用示例一:#!/usr/bin/pythonimport mymodulemymodule.sayhi()print('version',mymodule.__version_原创 2017-06-13 12:25:49 · 271 阅读 · 0 评论 -
python第19篇之-列表的使用
#!/usr/bin/pythonshoplist = ['apple','mango','carrot','banana']print('i have',len(shoplist),'item to purchase')print('These items are:',end=' ')for item in shoplist: print(item,end=' ')pri原创 2017-06-13 12:46:19 · 220 阅读 · 0 评论 -
python第20篇之--元组的使用
#!/usr/bin/pythonzoo = ('python','elephant','penguin')print('Number of animals in the zoo os',len(zoo))new_zoo = ('monkey','camel',zoo)print('Number of the cages in the new zoo is',len(new_zoo))原创 2017-06-13 12:52:09 · 296 阅读 · 0 评论 -
python第21篇--字典的使用
#!/usr/bin/pythonab = {'Swaroop' :'swaroop@swaroopch.com', 'Larry' :'larry@wall.org', 'Matsumoto':'matz@ruby-lang.org', 'Spammer' :'spammer@hotmail.com'}print("Swaroop's add原创 2017-06-13 13:02:44 · 238 阅读 · 0 评论 -
python第22篇之--列表操作
#!/usr/bin/pythonprint('Simple Assignment')shoplist = ['apple','mango','carrot','banana']mylist = shoplist #这里只是把mylist也指向了shoplist列表,程序中现在只有一个列表,mylist相当于别名del shoplist[0]print('shoplist is',原创 2017-06-13 13:18:19 · 200 阅读 · 0 评论 -
python第23篇之-最简单的类使用(面向对象编程)
#!/usr/bin/pythonclass person: passp = person()print(p)这里定义一个最简单的类person,类内容为pass,也就是为空。最后p=person() 来创建一个对象,并打印对象的地址原创 2017-06-14 06:50:02 · 272 阅读 · 0 评论 -
python第24篇之--类的初始化(面向对象编程)
#!/usr/bin/pythonclass person: def __init__(self,name): self.name=name def sayhi(self): print('hello,my name is',self.name)p = person('swaroop')p.sayhi()这里person类定义了原创 2017-06-14 06:57:17 · 602 阅读 · 0 评论 -
python第25篇之--类的继承
#!/usr/bin/pythonclass schoolMember: '''Represent any school member''' def __init__(self,name,age): self.name=name self.age = age print('(Initialize schoolMember:{0})'原创 2017-06-14 07:24:25 · 305 阅读 · 0 评论 -
python第26篇之--文件IO
#!/usr/bin/pythonpoem = '''programming is funwhen the work is doneif you wanna make your work also fun:usr python!'''f = open('poem.txt','w')f.write(poem)f.closef = open('poem.txt')while原创 2017-06-14 07:29:43 · 320 阅读 · 0 评论 -
python第27篇之--异常
#!/usr/bin/pythontry: text = input('Enter something-->')except EOFError: print('Why did you do an EOF on me?')except KeyboardInterrupt: print('You cancelled the operation.')else:原创 2017-06-14 07:38:29 · 239 阅读 · 0 评论 -
python第28篇--异常
#!/usr/bin/pythonimport timetry: f = open('poem.txt') while True: line = f.readline() if len(line) == 0: break print(line,end=' ') time.sleep(2)原创 2017-06-14 07:43:29 · 310 阅读 · 0 评论 -
获取在线帮助
开始写python程序时,对于导入的模块不清楚有什么具体函数,然后了解了有什么函数把,不清楚函数的具体使用方法。有没有一个像linux下的男人(man)一样的东西呢?当然有了。在python shell中开发时,查询模块中有什么函数的方法:(如要查询模块array的内置函数)import arrayhelp(array)这样就ok了。然后定义了一个数组cast=[ "原创 2017-09-22 17:44:13 · 204 阅读 · 0 评论 -
python第14篇--return
#!/usr/bin/python#filename return.pydef maximum(x,y): if x > y: return x else: return yprint(maximum(4,5))结果:5原创 2017-06-13 11:28:46 · 203 阅读 · 0 评论 -
python第13篇--空函数
#!/usr/bin/pythondef somefunction(): passprint(somefunction())结果输出:nonepass为关键字,表示无操作原创 2017-06-13 11:25:29 · 500 阅读 · 0 评论 -
python第一篇
#!/usr/bin/python#Filename:helloword.pyprint('hello world') 首先这里第一行 #!告诉shell使用什么解释器,这里指定了python解释器 其中“#”开头的是注释信息,解释器不进行解释 最后是一句打印 ,打印出 hello world 到这里就开始了python的学习之旅原创 2017-06-09 17:43:22 · 200 阅读 · 0 评论 -
python第二篇(format)
#!/usr/bin/python#Filename:format.pyage = 25name = 'saroop'print('{0} is {1} years old'.format(name,age))print('why is {0} playing with that python'.format(name))结果:[(3) root@Fedora~/Note原创 2017-06-09 17:51:07 · 422 阅读 · 0 评论 -
python第三篇-变量
#!/usr/bin/python#Filename:var.pyi = 5print(i)i = i + 1print(i)s = '''This is a mutil-line string.this is the second line'''print(s)结果:[(4) root@Fedora~/Note/python]#./2var.py 56Th原创 2017-06-09 17:57:11 · 146 阅读 · 0 评论 -
python第四篇-if
#!/usr/bin/pythonnumber = 23guess = int(input('Enter an integer : '))if guess == number: print('Congratulations,you guessed it.') print('(but you do not win any prizes)')elif guess < numb原创 2017-06-09 18:11:02 · 283 阅读 · 0 评论 -
python第五篇-while
#!/usr/bin/python#fileName:while.pynumber = 23running = Truewhile running: guess=int(input("enter an integer:")) if guess==number: print("Congratulatio,you guess it") run原创 2017-06-12 07:49:42 · 279 阅读 · 0 评论 -
/usr/bin/python^M: 解释器错误: 没有那个文件或目录(问题解决)
遇见问题因为linux在虚拟机中,所以就在本地敲python代码,敲完后再拿到虚拟机去执行,再输入./filename.py时,就遇到这样的一个问题:bash: ./filename.py: /usr/bin/python^M: 解释器错误: 没有那个文件或目录开始还以为是自己的python路径不对,但用which python命令查看却发现路径已经配置对了。因为有另一种执行方转载 2017-06-13 09:36:43 · 17210 阅读 · 1 评论 -
把linux环境中的python设置为python3
执行python脚本时,老是出现一些错误,后来发现只要手动执行python3 filename 就没有错误了。这时才觉得要把环境中默认的python设置为python3.具体执行如下:[(45) root@Fedora~/Note/python]#file /usr/bin/python/usr/bin/python: symbolic link to `python2'[(原创 2017-06-13 09:56:56 · 6959 阅读 · 0 评论 -
python第六篇之break
#!/usr/bin/python#filename:break.pywhile True: s = input('enter something:') s = s.replace('\r','') if s == 'quit': break print('length of the string is',len(s))print('done原创 2017-06-13 10:15:19 · 247 阅读 · 0 评论 -
python第七篇之continue
#!/usr/bin/python#filename:continue.pywhile True: s = input('Enter something:') if s == 'quit': break; if len(s) < 3: print('too small') continue print('Inpu原创 2017-06-13 10:25:41 · 195 阅读 · 0 评论 -
NameError: name 'raw_input' is not defined
python3.x中不再有raw_input函数,raw_input函数和input等效,使用input函数就可以了。原创 2017-06-13 10:36:45 · 497 阅读 · 0 评论 -
python第八篇之-函数(1)
#!/usr/bin/pythondef sayhello(): print('hello world')sayhello()sayhello()s = input()print(s)这里定义一个函数:def sayhello(): print('hello world')这里的函数功能就是打印一句hello world然后调用两次:sayhello原创 2017-06-13 10:39:09 · 152 阅读 · 0 评论 -
python第九篇之-函数帮助信息(doc)
#!/usr/bin/pythondef printMax(x,y): '''Prints the maximum of two numbers. The two values must be integers''' x = int(x) y = int(y) if x > y: print(x,'is the maximum原创 2017-06-13 10:52:10 · 907 阅读 · 0 评论 -
python第十篇之-全局变量
#!/usr/bin/python#filename func_global.pyx = 50def func(): global x print('x is',x) x = 2 print('changed global x to',x)func()print('Value of x is',x)结果:x is 50changed原创 2017-06-13 11:01:10 · 210 阅读 · 0 评论 -
python第11篇-局部变量
#!/usr/bin/python#filename func_local.pyx = 50def func(x): print('x is',x) x = x + 1 print('changed local x to',x)func(x)print('x is still',x)结果:x is 50changed local x to 5原创 2017-06-13 11:05:39 · 286 阅读 · 0 评论 -
python第12篇之-函数的嵌套定义以及关键字nonlocal使用
#!/usr/bin/python#filename func_nonlocal.pydef func_outer(): x = 2 print('x is',x) def func_inner(): nonlocal x x = 5 func_inner() print('changed local x to原创 2017-06-13 11:22:17 · 567 阅读 · 0 评论 -
python包的记录
array:数组模块string:字符串处理模块原创 2017-09-25 06:52:32 · 193 阅读 · 0 评论