name = "Ethan Du"
print("My name is ", name)
info0 = ‘‘‘ ------info of %s------ name:%s age:%s job:%s ‘‘‘ % (,,age,job)
info1 = ‘‘‘
------info of {_name}------
name:{_name}
age:{_age}
job:{_job}
‘‘‘.format(_name=name, _age=age, _job=job)
= ‘------info of {_name}------\n‘ ‘name:{_name}\n‘ ‘passwd:{_passwd}\n‘ ‘-----------------------------‘.format(_name=name,_passwd=passwd)
name = "Ethan Du" name1 = "HAHA" print(name,name1,sep=‘ ‘,end=‘.‘) STDOUT:Ethan Du HAHA.
sys.stdout = (open(‘log.txt‘),‘a‘) import sys temp = sys.stdout sys.stdout = open(‘log.txt‘,‘a‘) print(‘test‘) sys.stdout.close() sys.stdout = temp print(‘test‘)
age = int(input(‘guess age: ‘))
if age == 50:
print(‘yes‘)
elif age > 50:
print(‘younger‘)
else:
print(‘older‘)
count = 0
while count != 10:
if count == 9:
print(‘count:‘,count)
else:
print(count)
count +=1
else:
print(‘count:‘,count)
print u.split(‘.‘,-1) #分割最多次(实际与不加num参数相同)
[‘www‘, ‘doiido‘, ‘com‘, ‘cn‘]
u1,u2,u3 = u.split(‘.‘,2) #分割两次,并把分割后的三个部分保存到三个文件
print u1
www
print u2
doiido
print u3
com.cn
str="hello boy<[www.doiido.com]>byebye"
print str.split("[")[1].split("]")[0]
www.doiido.com
print str.split("[")[1].split("]")[0].split(".")
[‘www‘, ‘doiido‘, ‘com‘]
代码:
#Author:Ethan Du
count = 0
while True:
flag = 0
username = input(‘Username: ‘)
password = input(‘Password: ‘)
if username == ‘‘ or password == ‘‘:
print(‘Username or Password is empty, please input again‘)
continue
with open(‘user_file‘,‘r‘) as file:
for key in file:
if key.split()[0] == username and count != 3:
with open(‘lock_file‘,‘r‘) as lock:
for dlock in lock:
if dlock.split()[0] == username:
print(‘too much wrong login, exit‘)
exit()
if key.split()[1] == password:
print(‘Welcome to system‘)
flag = 1
exit()
else:
print(‘Wrong password, please input again‘)
count += 1
if count == 3:
with open(‘lock_file‘,‘w‘) as lock:
lock.write(username)
count = 0
print(‘too much wrong login, exit‘)
exit()
flag = 2
break
if flag == 0:
print(‘username is not exsit, please input correct username‘)
原文:http://www.cnblogs.com/ethandyp/p/6322523.html