Python入门系列Day1
格式化输出的几种写法:
name=input('Name:\n')
age=input('age:\n')
job=input('job:\n')
salary=input('salary:\n')
info='''
-----info of {_name}-----
Name:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
''' .format(_name=name,
_age=age,
_job=job,
_salary=salary)
print(info)
name=input('Name:\n')
age=input('age:\n')
job=input('job:\n')
salary=input('salary:\n')
info2='''
-----info of %s-----
Name:%s
Age:%d
Job:%s
Salary:%d
''' %(name,name,age,job,salary)
print(info2)
While循环
guess_age_oldboy = 43
count=0
#while True:
# if count==3:
# break
while count<3:
guess_age=int(input('guess age:\n'))
if guess_age==guess_age_oldboy:
print('yes, you got it')
break
elif guess_age > guess_age_oldboy:
print('think smaller')
else :
print('think bigger')
count+=1
if count==3:
countine_confirmation=input('do you want to keep guessing...?(Y/N)')
if countine_confirmation=='Y':
count=0
else:
break
--Break跳出当前循环,continue跳出本次循环跳转到下一次循环
For循环的简单使用
for i in range(0,10,2):
print('------------',i)
for j in range(10):
print(j)
if j>5:
break
对于Python而言,单引号与双引号没有差异,只是在用引号套引号时,必须用区分使用,即用单引号套双引号或者用双引号套单引号;