一.上节课回顾
1. 编译型:
将源码一次性全部编译成二进制. C
优点:执行效率高.
缺点:开发效率慢,不可跨平台使用. 解释型:
当程序执行时,代码一行一行的去解释成二进制. python
优点:开发效率快,可跨平台使用.
优点:执行效率相对低.
python2 python3 区别:
python2 各种语言的陋习,重复代码.
python3 简单清晰优美.
python的种类:cpython jpython 其他语言的python,pypy. 变量:
1,是由数字字母,下划线任意组合.
2,不能以数字开头.
3,不能是python中的关键字.
4,变量可描述性.
5,不能中文.
6,不能太长.
7,下划线格式.
常量:
理论上不能更改,Python中大写的变量就是常量.
注释:#单行
'''被注释内容''' """被注释内容"""
数据类型:
int
范围,和运算.
str
python中 带引号的都可以视为字符串. '' ""
s1 = '''
内容
'''
str + str 字符串的拼接
str * int
i = int(str) 全部由数字组成的字符串才能转化成数字
bool
True False
用户交互:input 字符串数据类型.
if:
if 条件:
结果
if 条件:
结果
else:
结果
if
elif
elif if
elif
elif
else: if
if
if if if while 条件:
结果 while :改变条件
break
break:结束循环.
continue:结束本次循环,继续下一次循环.
二、作业讲解

#1、使用while循环输入 1 2 3 4 5 6 8 9 10

# count = 0

# while count < 10 :

#     count += 1

#     if count == 7 :

#         continue

#     print(count)

#2、求1-100的所有数的和

pass

#3、输出 1-100 内的所有奇数

# a = 0

# i = 0

# while i < 50:

#     a = 2*i+1

#     i += 1

#     print(a)

# count = 1

# while count < 100:

#     print(count)

#     count += 2

# count = 1

# while count < 100:

#     if count % 2 == 1:

#         print(count)

#     count += 1

#4、输出 1-100 内的所有偶数

#5、求1-2+3-4+5 ... 99的所有数的和

# sum  = 0

# count = 1

# while count < 100:

#     if count % 2 == 0:

#         sum = sum - count

#     else:

#         sum = sum + count

#     count += 1

# print(sum)

#6、用户登陆(三次机会重试)

i = 1

while i <= 3:

username = input('请输入你的账户')

password = input('请输入你的密码')

if username == 'lol' and password == '戒了':

print('欢迎登录')

break

else:

print('错误,请重新输入')

i += 1

if i == 4:

answer = input('想不想在试一试?/y')

if answer == 'y':

i = 1

else:

print('要不要脸呀')

三、今日内容大纲

1,上节内容回顾.

2,作业讲解.3,pycharm使用

4,格式化输出,while else
while else: 5.逻辑运算符 6,编码.
四、while格式化输出

'''

i = 1

while i < 4:

print(i)

if i == 2:break

i += 1

else:

print('正常循环完毕')

'''

#格式化:format  %s  %d

#第一种写法:

# name = input('请输入你的名字:')

# age = int(input('请输入你的年龄:'))

# score = int(input('请输入你的成绩:'))

#

# msg = '我叫%s,今年%d岁,成绩为%d分'%(name,age,score)

# print(msg)

#第二种写法:

# name1 = input('请输入你的名字:')

# age1 = input('请输入你的年龄:')

# score1 = input('请输入你的成绩:')

#

# msg = '我叫%(name)s,今年%(age)s岁,成绩为%(score)s分'\

#       %{'age':age1,'name':name1,'score':score1}

# print(msg)

#

msg = '我叫%s,今年%d岁,学习进度为2%%' %('太白',21)

print(msg)

五、逻辑运算符

#优先级

# print(2 > 1 and 3 > 4)

# print(2 > 1 or 3 > 4)

# print(not 2 > 1)

#() > not > and > or

# a = 2 > 1 and 2 < 3 or 2 > 4 and 1 < 5 or 7 < 4

# print(a)

#1,前后都是比较的条件

# print(3 > 4 or 4 < 3 and 1==1)  # F

# print(1 < 2 and 3 < 4 or 1>2 )  # T

# print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)  # T

# print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)  # F

# print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F

# print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F

#2,前后都是数字

# print(1 or 2)

# print(2 or 3)

# print(0 or 2)

# print(0 or 3)

# print(1 and 2)

# print(0 and 3)

# x or y if x 为 True,则值是x ;else:值是y.

# and 与or相反

'''

ps: str ---> int  int(str) 字符串必须是数字组成

int----> str  str(int)

int ---> bool 非0 ----> True

0 -----> False

'''

# print(1 or 3 and 4 or 5)

# print(2 > 1 or 1 and 3 < 2)

六、编码的历史

战争时期:

发电报,发的是高低电频,实际上是01010101

今    0000 0001

晚    0000 0101

嗨    0000 0111

去呀  0000 1001

00000001 00000101 00000111 00001001

计算机:

储存文件,或者是传输文件,实际上是010101010

计算机创建初期,美国,二进制,

密码本:

ascii

00000001

01000001 01000010 01000011   ABC

因为全球语言很多,ascii不足以存储这么多对应关系,创建了一个超级密码本:万国码unicode

8 位 == 1个字节.

hello h一个字符,e一个字符,he就不是一个字符.

中国:中是一个字符,国是一个字符.

unicode :

创建之初,16位,2个字节,表示一个字符.

英文:  a b c  六个字节   一个英文2个字节

中文   中国   四个字节  一个中文用2个字节

改成 32位,4个字节,表示一个字符.

a  01000001 01000010 01000011 00000001

b  01000001 01000010 01100011 00000001

中 01001001 01000010 01100011 00000001

浪费资源.

对Unicode进行升级:  utf-8

utf-8 用最少用8位数,去表示一个字符.

英文:           8位,1个字节表示.

欧洲文字:       16位,两个字节表示一个字符.

中文,亚洲文字:   24位,三个字节表示.

utf-16 用最少用16位数.

gbk:

国标,只能中国人自己用, 一个中文用16位,两个字节表示.

单位转化:

8位bit  8bit == 1bytes

1024bytes == 1kB

1024KB == 1MB

1024MB == 1GB

1024GB == 1TB

七、 in not in

#in not in

# s = 'fkdjsaalexgfdjlk'

# print('alex' in s)

# not in

comment = input('请输入你的评论')

s1 = '苍老师'

if s1 in comment:

print('有非法字符,从新输入')

else:

print('评论成功')

python基础1 day2的更多相关文章

  1. Python基础篇-day2

    主要内容: for循环 while循环 格式化输出(2) 数据统计及记录 ############################################################# 1 ...

  2. python基础之day2

    python基本数据类型 1.数字 int(整型)      在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647  在64位系统 ...

  3. Python基础学习Day2

    一.格式化输出 需求格式化输出:姓名.年龄.工作.爱好 # 格式化输出 name = input('请输入用户名:') age = input('请输入年龄:') job = input('请输入你的 ...

  4. Python基础,day2

    程序练习 程序:购物车程序 需求: 启动程序后,让用户输入工资,然后打印商品列表 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时退出,退出时,打印已购买 ...

  5. Python基础知识-day2

    格式化输出 %占位符,s字符串,d 数字, 表示%  用%% name = input("请输入姓名: ") age = input("请输入年龄: ") he ...

  6. python基础一 day2 字符串操作

    s.capitalize()  s.upper()  s.lower() s.swapcase()   s.title()  s.center(20,"#")   s.expand ...

  7. python基础一 day2 数据类型

    int:        bool: 类型转换: str到int有条件,str必须是数字, "123e"是错误的 bool转换为int类型,需要int(x)  结果:  结果: 空字 ...

  8. python基础一 day2

    内容:   3%%s   输出:3%s       后面的全部转义 结果: 如果是因为执行break语句导致循环提前结束,就不会执行else. 单位换算: 编码方式: ascii  unicode u ...

  9. Day2 - Python基础2 列表、字典、集合

    Python之路,Day2 - Python基础2   本节内容 列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一, ...

随机推荐

  1. apache泛域名解析

    <VirtualHost *:80>    DocumentRoot "E:\work\phpStudy\WWW\ncpx\web"    ServerName ncp ...

  2. php-基础知识-apache服务器

    一.支持php的服务器有:iis.apache.lighted(德国制造).nginx(俄罗斯制造,功能强大[反向代理.服务器集群.流媒体服务器........].轻量) 二.今天主要分享apache ...

  3. Spring任务调度之Quartz集成

    推荐一个博客:http://blog.csdn.net/column/details/14251.html 基本概念 Job:是一个接口,只有一个方法void execute(JobExecution ...

  4. Linux目录结构介绍-http://yangrong.blog.51cto.com/6945369/1288072

    1.树状目录结构图 2./目录 目录 描述 / 第一层次结构的根.整个文件系统层次结构的根目录. /bin/ 需要在单用户模式可用的必要命令(可执行文件):面向所有用户,例如:cat.ls.cp,和/ ...

  5. SVN添加用户权限

    点击properties

  6. shiro中 UnknownAccountException

    一 shiro的session.request和response与服务端容器自身的这三个对象的关系 在web.xml中配置了一个Filter,拦截/*,所有的uri.在拦截器中还会调用ShiroFil ...

  7. Git详解之一:Git起步

    起步 本章介绍开始使用 Git 前的相关知识.我们会先了解一些版本控制工具的历史背景,然后试着让 Git 在你的系统上跑起来,直到最后配置好,可以正常开始开发工作.读完本章,你就会明白为什么 Git ...

  8. Android与javascript中事件分发机制的简单比较

    在前面两篇博客中,我们讨论了Android中的事件分发的相关内容,那么在本篇博客当中,我们就简单探讨一下html或javascript中的事件分发机制,并进行简单的对比. 在前端中,对事件进行绑定有三 ...

  9. NFS : device is busy

    unmount [ options ] -f : Force unmount (in case of an unreachable NFS system). -l  : Lazy unmount. D ...

  10. Python 词云分析周杰伦《晴天》

    一.前言满天星辰的夜晚,他们相遇了...夏天的时候,她慢慢的接近他,关心他,为他付出一切:秋天的时候,两个人终於如愿的在一起,分享一切快乐的时光但终究是快乐时光短暂,因为杰伦必须出国深造,两人面临了要 ...