解释器问题
# 可移植性的对比,如果你的代码移植到的机器,python并未安装在/usr/bin/python这里,就使用第二种;
#!/usr/bin/python
#!/usr/bin/env python
中文问题
#coding:utf-8
#coding=utf-8
#encoding:utf-8
#encoding=utf-8
#encoding:-*- utf-8 -*-
编码格式:
ASCII:美国人发明了计算机,1个字节(8位)去存储一个英文字符,2^8=256;
Unicode:2个字节(16位)去存储一个字符,2^16,65536;
# GB2312:
utf-8:在编程过程中,英文多,中文少。如果是英文字符,就用一个字节去存储;如果是中文用3个字节去存储;
python的IDE工具
- sublime
- eclipse
- pycharm
快捷键和技巧
- ctrl+alt+s:设置
- alt+insert:新建(文件,目录,包)
- ctrl + s:保存
- Delete:删除(文件,目录,包)
- ctrl + /: 快速注释(或取消)一行或多行
- shift+alt+N:
- ctrl+d: 快速复制一行
shift+delete:快速删除一行
- 用户登陆v1:
1). 假设系统中的用户名”root”,密码为”westos”;
2). 如果用户输入用户名和密码均正确显示”login ok”
如果用户名错误,显示”user is not exist”
如果密码错误,显示”password is no ok”
3). 只有三次登陆机会,超过三次,显示”count is bigger than 3”
- 用户登陆v1:
#!/usr/bin/env python
#coding:utf-8
"""
file: denglu.py
date: 2017-08-24 8:28 PM
author: xsh
desc:
"""
user = "root"
passwd = "westos"
for i in range(1,4):
username = raw_input("Please input username:")
if username == user :
password = raw_input("Please input password:")
if password == passwd :
print ("login ok")
exit()
else :
print("password is no ok")
else :
print("user is not exist")
while i > 2 :
print ("count is bigger than 3")
exit()
2.乘法表
#!/usr/bin/env python
#coding:utf-8
"""
file: chengfa.py
date: 2017-08-24 9:19 PM
author: xsh
desc:
"""
for i in range(1,10):
for j in range(i,10):
print('{}x{}={}'.format(i,j,i*j) )
#print("%d*%d=%2d"%(i,j,i*j))
3.简单的整理图