Python常用知识点
来源:互联网 发布:穷人该不该谈恋爱 知乎 编辑:程序博客网 时间:2024/05/16 07:58
1. for
#!/usr/bin/pythonfor letter in 'chinese':if letter == 'n':passprint "this is a pass block"print 'Current Letter:',letterfor zimu in 'Python':if zimu == 'h':breakprint "current zimu = ",zimuprint "Good bye"
2. while
#!/usr/bin/pythonval = 11while val > 0:print "current value = ",valval = val - 2if val == 3:breakvar = 11while var > 0:print "value = ",varvar = var - 2if var == 3:continueprint "Over end"
3. function
def关键字
#!/usr/bin/pythondef printstr(strs):"this function is passing into a string"print strs;return;printstr("cat and dog")printstr("I like it")
4. list
#!/usr/bin/pythonli=["dog","cat","bull","sheep","pig","chicken","horse"]print li #prints all elementsprint li[0] #print first elementprint li[1] #print second elementprint li[1:3] #print element which index is 1 and 2
5. dict
#!/usr/bin/pythonwords = {}words["yes"] = "1"words["no"] = "0"words["age"] = "25"print words["age"]print words["no"]print wordswords["yes"] = "dui"words["name"] = "yanxia"del words["no"]print words
6. string
#!/usr/bin/pythonsen="this is a book"qa="book"if qa == sen:print('strings equal')if qa in sen:print(qa + " found in " + sen)str="In Python,\nyou can use special characters in strings.\nThese special characters can be..."print(str)
7. tuple
#!/usr/bin/pythonx = (2,3,4,5)x = x + (7,8,1)print(x)lis = ["book","cup","pen","eraser","tea"]tu = tuple(lis) #list->tupleprint(tu)y = (4,5)lis = list(y) #tuple->listprint(lis)animal = ("cock","rabbit","mouse","hen","fog")str1 = ' '.join(animal)print(str1)per = tuple(sorted(animal))print(per)
8. class
#!/usr/bin/pythonclass JustCounter:__secretCount = 0def count(self):self.__secretCount +=1print self.__secretCountcounter = JustCounter()counter.count()counter.count()
0 0
- python 常用知识点
- Python常用知识点
- python 常用知识点总结
- python常用知识点
- 机器学习-->python常用知识点
- python的一些常用知识点备用
- python知识点(一):python检测代码效率常用方法
- 常用知识点
- 常用知识点
- python基础之列表常用操作及知识点小结
- python知识点
- python 知识点
- Python知识点
- python知识点
- Python 知识点
- Python知识点
- Python知识点
- python知识点
- 【网络流24题】最长不下降子序列问题
- nyoj--115 城市平乱(最短路径)
- C++容器类(来自yeahask的博客http://blog.sina.com.cn/yeahask )
- 解决iOS的工程开发遇到的问题
- LeetCode : Valid Sudoku [java]
- Python常用知识点
- 第一次上机实验2
- Tomcat Session_Cluster(四)
- yum安装g++
- Java 异常 越界问题
- 浅谈HTTP中Get与Post的区别
- 关于封装的理解
- Undefined symbols for architecture x86_64:的一种可能的解决方法
- 不再以讹传讹,GET和POST的真正区别