我在学python

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 here
else:
        print 'Done'

3.for loop

for i in range(1,5,2):
        print i
else:
        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:
                break
else:
        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=5
y=6
printMax(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=5
printMax(10)
print x
we do not need care about the sequence

9.

#!/bin/python
if __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/python
def sayhi():
        print 'hi,this is my module'
version = '0.1'

#!/bin/python
import mymodule
mymodule.sayhi()
print 'version',mymodule.version

11.from......import





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值