我在学python
来源:互联网 发布:淘宝送的优酷会员在哪 编辑:程序博客网 时间:2024/05/21 08:58
1.raw_input
guess = int(raw_input('Enter an integer : '))
2.while loop
while running: guess = int(raw_input('Enter an integer : ')) if guess == number: running=False print 'Congratulations, you guessed it.' # New block starts here print "(but you do not win any prizes!)" # New block ends here elif guess < number: print 'No, it is a little higher than that' # Another block # You can do whatever you want in a block ... else: print 'No, it is a little lower than that' # you must have guess > number to reach hereelse: print 'Done'
3.for loop
for i in range(1,5,2): print ielse: print "the loop is over"the default step for range is "1"
4.break the loop
for i in range(1,5,2): print i if i==1: breakelse: print "the loop is over"
5.len
len(s) print the lenth of the string s
6.python function
def sayhello():
print "hello python"
sayhello()
7.global var
def printMax(a,b): global x x=100 if a>b: print a,"is maximum" else: print b,"is maximum"x=5y=6printMax(x,y)print x
8.default arg
def printMax(a,b=1010): global x x=100 if a>b: print a,"is maximum" else: print b,"is maximum"x=5printMax(10)print x
we do not need care about the sequence
9.
#!/bin/pythonif __name__ == '__main__': print 'this is being run by himself'else: print 'I am being run by others'
$ python using_name.py
This program is being run by itself
$ python
>>> import using_name
I am being imported from another module
>>>
10.import
#!/bin/pythondef sayhi(): print 'hi,this is my module'version = '0.1'
#!/bin/pythonimport mymodulemymodule.sayhi()print 'version',mymodule.version
11.from......import
- 我在学python
- 转:你们以为我在学C++?其实我在学 Python(pezy)
- 我在学英语
- 小学生都在学Python
- 我是新手,我在学Android
- 我在学JavaScript中的循环
- 我在学JavaScript中的循环
- 在学python(要点整理)
- GoodZhang在学Python(一)--初探Python
- 我自己在学arm7——ourdev
- [我在学Android]Android四大组件
- GoodZhang在学Python(六)--字符串格式化
- GoodZhang在学Python(八)--基本数据结构
- 最近在学python web初体验
- 当我参加培训的时候,我在学什么?
- GoodZhang在学Python(二)--Python环境安装配置&HelloWorld
- GoodZhang在学Python(四)--Python中的函数
- 写了几年web之后我在学什么?
- 黑马程序员-----枚举
- NSRunloop
- unity3d 游戏对象消失三种方法的区别(enabled/Destroy/active)
- 关于分别import导入每个文件和*操作哪个更有效率
- Linux & C记录
- 我在学python
- javascript中对数组的操作
- extjs combobox下拉框显示位置问题
- spring 事务详解
- Chrome 最小字体12px
- IS_ERR()
- NSRunLoop 理解
- boost学习笔记(01)
- sql server2005系统表