python基础
1.变量
2.字符编码
Python 2 里面需要指定字符编码,(python 3 不需要)
# -*- coding:utf-8 -*-
#Author:Bai
name = “你好,世界”
print (name)
3. 注释
3.1单行注释
单行注释用#注释
3.2多行注释
多行注释用’’’ ‘’’进行注释
可以用来定义多行变量用法:
msg = ”’
name = “你好,世界”
world = “china”
print (name)
”’
print (msg)
4.用户输入
#Author:Bai
name = input ("name:")
age = int(input ("age:"))
print (type(age))
job = input ("job:")
salary = input ("salary:")
info = '''
------ info of %s ----
name:%s
age:%d
job:%s
salary:%s
''' % (name,name,age,job,salary)
print (info)
info2 = '''
------ info of {_name} ----
name:{_name}
age:{_age}
job:{_job}
salary:{_salary}
'''.format(_name=name,
_age=age,
_job=job,
_salary=salary
)
print (info2)
5.while循环
age_of_oldboy = 45
count = 0
while count <3:
guess_age = int(input("guess_age:"))
if guess_age == age_of_oldboy:
print("yes,you got it.")
break
elif guess_age > age_of_oldboy:
print("think smaller...")
else:
print("think bigger...")
count +=1
else:
print("you try too many time.get off")