一.上节课回顾
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. Docker(十三):OpenStack部署Docker集群

    1.介绍 本教程使用Compose.Machine.Swarm工具把WordPress部署在OpenStack上. 本节采用Consul作为Swarm的Discovery Service模块,要利用C ...

  2. SSH远程登录密码尝试

    import threading #创建一个登陆日志,记录登陆信息 paramiko.util.log_to_file('paramiko.log') client = paramiko.SSHCli ...

  3. Java企业微信开发_11_异常:java.net.UnknownHostException: qyapi.weixin.qq.com

    原因: 网络原因导致 dns解析失败. 解决方案: 方案一 : 1.查看你的服务器能否ping通外网,不过不行说明你的网络出了问题.     (我的情况是客户的应用服务器只能内网访问,所以是网络出问题 ...

  4. 让你彻底弄清offset

    很多初学者对于JavaScript中的offset.scroll.client一直弄不明白,虽然网上到处都可以看一张图(图1),但这张图太多太杂,并且由于浏览器差异性,图示也不完全正确. 图一 不知道 ...

  5. js写基础insertAfter()方法

    //DOM没有提供insertAfter()方法 function insertAfter(newElement, targetElement){ var parent = targetElement ...

  6. 笔记-NSArray 逆序reverseObjectEnumerator 及 NSEnumerator 遍历

    //1.原始数组 NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1",@"2",@&qu ...

  7. 如何实现虚拟机(VirtualBox)中的Ubuntu与Windows XP间的数据共享

    环境: 主机是Windows XP系统 虚拟机与Ubuntu的版本分别为: VirtualBox-3.2.12-68302-Win ubuntu-10.10-desktop-i386 前提:已安装Vi ...

  8. HTTP状态码、请求方法、响应头信息

    HTTP状态码 当浏览者访问一个网页时,浏览者的浏览器会向网页所在服务器发出请求.当浏览器接收并显示网页前,此网页所在的服务器会返回一个包含HTTP状态码的信息头(server header)用以响应 ...

  9. 用元类和__getattribute__改变类属性的读取方式

    首先,需要知道两点: 类本身是type类的实例 __getattribute__ 可以改变类实例的属性的读取方式(http://www.cnblogs.com/blackmatrix/p/568148 ...

  10. Python装饰器的解包装(unwrap)

    在Python 3.4 中,新增一个方法unwrap,用于将被装饰的函数,逐层进行解包装. inspect.unwrap(func, *, stop=None) unwrap方法接受两个参数:func ...