迈向大声的第二天

day 002   Python基础篇

2018-10-12 17:46:36

1.pycharm的使用小技巧

调节字体大小找到setup 输入 mouse genera 设置编码格式utf-8 控制台字体 console
ctrl+d 复制当前行
ctrl+E 删除当前行
shift+enter 快速换行
ctrl+ 快速注释
Shift+tab 取消缩进
ctrl +H 替换
ctrl+ - 折叠当前代码

debug模式 右侧点击

 ctrl+z 撤销一行

python 一些常用方法:

http://edu.51cto.com/center/course/lesson/index?id=163794

ps:

#用户登录3次密码尝试
i=0
while i < 3  :
    username = input("请输入账号")
    if username == "king" :
        print("登录成功")
        break
    else:
        print("登录失败 请重新输入")
    i += 1
用户输入3次

2.格式化输出


格式化输出
format
ps:格式化输出信息

name = input("请输入姓名:")
age = input("请输入年龄:")
msg = "我的名字是%s,我今年%s岁"%(name,age)
print(msg)
显示学生信息

3.while-else 的使用细则

当while内的程式正常执行时才会 执行else 

count = 0
while count<=5 :
  count+=1
  if count == 3: break
  print("Loop",count)
  else:
    print("循环正常执行完") #有break执行else 或者程序突然中止
print("最后一行")

4.编码与所占字节数 

python2 ASCII码 2个字节表示一个中文
unicode 一个中文用四个字节表示
utf-8 3个字节表示一个中文 %%%%
GBK 只包含中文 国内使用 一个中文用2个字节

5.逻辑运算

// 整除

逻辑运算 and or not
优先级 () not and or
or print(0 or 2) 2 #重点 重点 重点      or  谁先时True 打印谁
and print (1 and 2) 2   最后一个为true 打印最后一个
print(0 or 4 and 3 or 2 ) 返回3

bool 非零为真

http://www.cnblogs.com/jin-xin/articles/7459977.html

原文地址:https://www.cnblogs.com/zhenqk/p/9779942.html