码迷,mamicode.com
首页 > 编程语言 > 详细

First lesson of python

时间:2016-06-21 22:46:55      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:python   false   

1.    assigment  operator

a=1

a+=1    equal     a=a+1


2.    Conditional operator

‘‘==‘‘ doesn‘t mean ‘‘=‘‘

e.g.      a=1

            b=2

            bool(a==b) => false


3.    if...else

       if []:      if "":      # false 

        

        if (condition expression1):

        ...

        elif (condition expression2):

        ...

        elif (condition expression3):

        ...

        else:

        ...

4. Question. Why there is no "CASE" in python.

    Answer:   Due to  dict

e.g. 

def    fun1():

                print (‘a‘)

del    fun2():

                print (‘b‘)

del    fun3():

                print (‘c‘)

dict={‘1‘:fun1,‘2‘:fun2,‘3‘:fun3}

dict[‘1‘]()    #d[x] (arguments)


def add(x,y):

    return x+y

...


def f()

        ....

f # function name

f() # execute function


if __name__ = ‘__main__‘ # main function

 

userdict = {}

user, pw=userinfo.strip().split(‘,‘)

userdict[user]=pw


a=open(‘x.txt‘,‘a‘)

a.write (‘\n%s‘%(name))

a.close()


First lesson of python

标签:python   false   

原文地址:http://luluuy.blog.51cto.com/279347/1791515

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!