python Basic usage
2015-05-10 22:11
225 查看
__author__ = 'student' l=[] l=list('yaoxiaohua') print l print l[0:2] l=list('abc') print l*3 l.append(4) print l l.extend('de') print l print l.count('a') l.sort() print l l.reverse() print l l[0:2]=[1,2,3] print l print list(map (ord,'spam')) l = ['abc', 'ABD', 'aBe'] l.sort(key=str.lower) # sort in place not return new object, be ware of this print l print sorted(l, key=str.upper, reverse=True) #return new object not change l print l ''' while True: reply=raw_input("please input what you want to say:") if reply=='exit': break else: print reply.upper() ''' print 100**2 a,b='A','B' print a print a,b L = [1, 2] M = L # L and M reference the same object L = L + [3, 4] # Concatenation makes a new object print L, M # Changes L but not M L = [1, 2] M = L L += [3, 4] # But += really means extend print L, M # M sees the in-place change too! L = L.append(4) # But append returns None, not L print(L) # So we lose our list! None data = (123, 'abc', 3.14) for i, value in enumerate(data): print i, value import re m=re.match(r'\d+','123:abc') if m is not None : print m.group() import random for i in range(1,10): print random.choice(xrange(10)) l=[1,2] sum= lambda a,b:a+b print 'sum is :' , sum(*l) # parse the list to function parameters d={'a':1,'b':2} print 'sum is ', sum(**d) # ** parse the dictionary to function parameters with open(r'd:\test.txt','w') as file: # with clause the system will release resource automatically for x in range(0,26,1): file.write(chr(ord('a')+x)) file.write('\n') with open(r'd:\test.txt','r') as file: for line in file: print line.rstrip() # rstrip remove the end line in the string
相关文章推荐
- python网页模板mako,basic-usage文档
- Python Basic Examples
- spark-2.2.0-bin-hadoop2.6和spark-1.6.1-bin-hadoop2.6发行包自带案例全面详解(java、python、r和scala)之Basic包下的JavaTC.java(图文详解)
- A Basic Example of Threads Synchronization in Python, python中的线程同步示例
- Python 函数——logging.basicConfig
- git_community_book:ch2_basic_usage
- OGRE中级教程二 RaySceneQueries and Basic Mouse Usage
- 【OpenCv-Python】六、Basic Operations on Images
- the usage of tuple in python
- Some basic javascript usage
- DbHelper basic usage
- 8.1. datetime — Basic date and time types — Python v2.7.3 documentation
- 26 BasicUsageEnvironment基本使用环境——Live555源码阅读(三)UsageEnvironment
- python - Tkinter basic exapmle
- Summary on 20080616: Basic usage of Enum in Java1.5
- Operations on basic server (by Python)
- 笨办法学 Python · 续 练习 37:小型 BASIC
- spark-2.2.0-bin-hadoop2.6和spark-1.6.1-bin-hadoop2.6发行包自带案例全面详解(java、python、r和scala)之Basic包下的SparkPi.scala(图文详解)
- Python_Jython 2.2.1 Basic Install