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()
原文地址:http://luluuy.blog.51cto.com/279347/1791515