python基础

1.变量

变量名可以包括字母、数字、下划线,但是数字不能做为开头

系统关键字不能做变量名使用

除了下划线之个,其它符号不能做为变量名使用

Python的变量名是除分大小写的

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")

 

6.for循环

for i in range(10):
print('----',i)
for j in range(10):
print(j)
if j >5:
break

 

 

posted @ 2018-01-14 15:21  一刀一个小朋友  阅读(136)  评论(0编辑  收藏  举报