day02笔记记录

一、今日摘要

循环、字符串格式化、运算符、编码、博客。

二、内容回顾

(一)计算机基础

计算机由硬件和软件组成。传统计算机的硬件一般有输入单元、输出单元,算数逻辑单元、控制单元及记忆单元,其中算术逻辑单元和控制单元合称为中央处理器(CPU)。

(二)安装解释器

py2和py3安装。

(三)语法:print/input:

(1)python2和python3的输入:

Python2的输入:

input():只支持正确的数值类型,不接受字符串输入。

raw_input():可接受数值和字符串,输出的类型均为字符型。

Python3的输入:

input():可接受数值和字符串,输出类型均为字符型。

(2)python2和python3的输出:(py2不需要括号,py3需要括号)

python2的输出:

print“你好”

python3的输出:

print(“你好”)

(四)字符类型

整形int。

字符串str。

布尔值boolen。

(五)条件语句结构

if  条件:
print(‘输出!’)
elif 条件:
print(‘输出!’)
else:
print(‘输出!’)

(六)编码类型:

assic(1字节);

unicode(4字节);

utf-8(1-3字节);

gbk;

bgk2312;

(七)练习,评分规则:

score=input('请输入你的成绩:')
score=int(score)
if score > 90:
print('you get :A')
elif score > 80:
print('you get :B')
elif score > 70:
print('you get :C')
else:
print('you get :D')

(八)10086练习

message='''欢迎致电100086:
1、话费查询;
2、流量服务;
3、业务办理;
4、人工服务;
'''
print(message) index=input('请输入你要服务号码:')
index=int(index) if index==1:
print('话费查询')
elif index ==2:
print('流量服务')
elif index==3:
content='''业务办理:
1、修改密码;
2、更改套餐;
3、停机;
'''
print(content)
vlaue=input('请输入业务办理号码:')
vlaue=int(vlaue)
if vlaue==1:
print('修改密码')
elif vlaue==2:
print('更改套餐')
elif vlaue==3:
print('停机')
else:
print('输入错误,请重新输入')
elif index==4:
print('人工服务')
else:
print('输入错误,请重新输入')

三、循环

while 的循环结构为:while else

(一) 请打印1,2,3,4,5,6,7,9,10

方法1:
count = 1
while count <= 10:
if count == 8:
pass
else:
print(count)
count += 1
方法2:
conut=1
while conut <=10:
if conut !=8:
print(conut)
conut+=1
方法3:
count = 1
while count < 8:
print(count)
count += 1
count =9
while count <= 10:
print(count)
count+=1
方法4:
count=1
while count<=10:
if count ==8 :
count+=1
continue
else:
print(count)
count+=1

条件是false时候执行else,break后不执行本while循环,continue后跳出本次循环,继续循环下次循环。

while 基本结构:while else

break

continue

while else

四、字符串格式化

(一) 占位符格式化

例子1:

name=input('姓名:')
do = input('在干什么:')
template = '%s 在教室,%s' %(name, do,)
print(template)

例子2:

template="我是%s,年龄%s,职业%s。" %("alex",73,'讲课',)
print(template)

占位符%s表示:字符串;

占位符%d表示:数字。

如果想打印出第二个%,需要在第二个%前再加一个%。

name=input('请输入姓名:')
template="%s现在手机的电量是100%%"%(name,)
print(template)

例子3:

name = input('your name is :')
age = input('your name is :')
job = input('your job is :')
hobby = input('your hobby is :')
msg = '''
-----------info of alex----------
name=%s
age=%s
job=%s
hobbie=%s
------------end-----------------''' data = msg % (name, age, job, hobby,)
print(data)

五、运算符

(一)运算符介绍

①%:取余数

②/:除法

③//:除法取整

例子:取奇数:

count=1
while count<=101:
if count%2==1:
print(count)
count+=1

例子:计算1-100之和:

count=0
total=0
while count<=101:
total=total+count
count+=1
print(total)

(二)运算符高级应用:

比较和赋值运算

=
+=
*=
/=
%=
**=
//=

(三)逻辑运算:

and
or
not

(1)or运算

①value=1 or 9

value=1

②value=0or9

value=9

③value=0or''

value=''

总结:x or y---if x is false ,then y,else x

如果有多个or条件,从左到右依次进行上述流程。

(2)and运算:

①v1=1 and 9

v1=9

②v1=1 and 0

v1=0

③v1=0 and 7

v1=0

④v1=0 and ''

v1=0

总结:x and y--if x is false,then x,else y

如果有多个and条件,从做到右依次进行上述流程。

(3)布尔运算

数字转布尔值:

①false:0、空字符串,None。

②其他都是true。

③布尔值转换成数字,只有0和1。

④布尔值转换成字符串,只有False和True

(4)not运算:

if x is false,then true,else false。

综合or,and:

v1=1 and 9 or and 6

v1=9

优先级:先计算and,再算or

六 、编码复习

(一)编码类型

ascii:1字节,8位,py2默认编码。

unicode:4字节,32位。

ecs2,2个字节

ecs4,4个字节

utf-8:1至3字节,(中文标示3个字节)。

utf-16,

gbk:(中文用2个字节)

gb2312:(中文用2个字节)

(二)单位:

8bit=1byte

1024byte=1kB

七、博客园基本使用

(一)博客文各属性介绍

①随笔:可以随便看

②文章:别人看不到,需要url才能看

③日记:只能自己看

(二)git版本管理工具

下载、安装、码云注册(保存代码)、创建仓库(创建文件夹)、写作业并提交。

(1)如何提交作业

在某个作业文件夹下作业

在文件夹上右键:

gitbase

在黑框里:git init,

用于git将当前文件夹管理起来

git add .

将当前文件夹的所有文件收集起来。

git commit -m “第二天的作业”,做个记录。

第一次时候需要:

git config --global user.name"崔永超"

git config --global user.email "cuiyongchao007@163.com"

git remote add origin https://gitee.com/cuiyongchao007/

项目名称

上传:

git push origin master

最新文章

  1. Android根据文件路径加载指定文件
  2. jquery对javascript事件的封装一览
  3. XSS攻击:获取浏览器记住的明文密码
  4. Delphi进制转换(二进制/十进制/十六进制)
  5. c# 利用 两个TREEVIEW控件完成TEENODE的鼠标拖动操作
  6. NOSQL的应用,Redis/Mongo
  7. attribute section的用法
  8. centos7 systemctl grub2
  9. subTree
  10. eclipse安装svn插件的多种方式
  11. oracle物理视图(转)
  12. angular4升级angular5问题记录之No NgModule metadata found for &#39;AppModule&#39;
  13. MySQL到MongoDB的数据同步方法!
  14. leetcode之Largest Rectangle in Histogram
  15. Linux虚拟机搭建本地yum源
  16. WMware workstation中几种网络连接的说明 【转】
  17. Heaps(Contest2080 - 湖南多校对抗赛(2015.05.10)(国防科大学校赛决赛-Semilive)+scu1616)
  18. puppet 横向扩展(一)
  19. 动态规划-LCS最长公共子序列
  20. es分布式文档系统_bulk api的奇特json格式与底层性能优化关系

热门文章

  1. jenkins里的定时构建
  2. Python文件写入时的编码问题解决
  3. suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))
  4. bash6——循环
  5. Jmeter使用代理录制web
  6. python进程与线程的操作
  7. 使用lib-flexible.js适配移动端UI设计750px设计图
  8. Java通过 Scanner 类来获取用户的输入
  9. Java中父类和子类代码执行顺序
  10. mybatis源码学习(三)-一级缓存二级缓存