python 2 days

1,格式化输出,%s  %d

2,复习昨日讲题

编译型:
将代码一次性全部编译成二进制,然后运行。
优点:执行效率高。
缺点:开发效率低,不能跨平台。
C
解释型:
代码逐行解释,边解释边执行。
优点:开发效率高,可以跨平台。
缺点:执行效率低。
python

变量:
1,必须由数字字母下划线任意组合。
2, 数字不能开头。
3,不能是Python中的关键字。
4,不能是中文。
5,不能太长。
6,要具有可描述性。

常量:不能改变的量,全部大写的变量为常量,放在文件起始。

基础数据类型:
int :运算。
str:
被引号引起来的都是字符串。
+ 拼接。str + str
* str * int。
bool
True,False

用户输入:input
python2x: raw_input()
input() 相当于eval()
python3x: input()

if
if 条件:
pass

if 条件:
pass
else:
pass

if 条件:
pass
elif 条件:
pass
elif 条件:
pass


if 条件:
pass
elif 条件:
pass
elif 条件:
pass
else:
pass

if 条件:
if ...
else:
pass
else:
if..
else:...

while 条件:
pass
break:直接跳出当前循环。
continue:结束本次循环,继续下一次循环。

3,while else

6,讲解昨天作业上6道题

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

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

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

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

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

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

# 1、使用while循环输入 1 2 3 4 5 6 8 9 10
# count = 1
# while count < 11:
# if count == 7:
# count += 1
# print(count)
# count += 1

# 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 = 0
# while i < 3:
# username = input('请输入用户名:')
# password = input('请输入密码:')
# if username == '婉容' and password == '123':
# print('登录成功')
# break
# else:
# print('用户名或者密码错误,请重新输入')
# i += 1

4,运算符

# print(2 > 1 and 3 < 4 or 8 < 10 and 4 > 5)
# 第一种情况 逻辑运算符前后都是比较运算
# 优先级概念:() > not > and > or,同一优先级从左至右以此计算。
# 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
# 第二种情况 逻辑运算符前后都是数字
'''
x or y if x True,return x,else y
'''
# print(3 or 5)
# print(2 or 5)
# print(0 or 5)
# print(-4 or 5)
# print(3 and 5)

# print(1 or 3 or 4 or 0)
# print(1 or 3 or 0)

# print(1 > 2 and 3 or 4)
'''
数字与bool值转化
int ---> bool 非零 True ,零 False
bool---> int True 1, False 0,
'''
# print(bool(100))
# print(bool(0))

7,格式化输出

# name = input('请输入名字:')
# age = input('请输入年龄:')
# sex = input('请输入性别:')
#
# msg = '我的名字是' + name + '我的年龄是' + age + '我的性别是' + sex
# print(msg)

msg = '''
------------ info of Alex Li -----------
Name : Alex Li
Age : 22
job : Teacher
Hobbie: girl
------------- end -----------------
'''
# 格式化输出 %占位符 s d
# name = input('请输入姓名:')
# age = int(input('请输入年龄:'))
# job = input('请输入工作:')
# hobby=input('请输入爱好:')
#
# msg = '''
# ------------ info of %s -----------
# Name : %s
# Age : %d
# job : %s
# Hobbie: %s
# ------------- end -----------------
# ''' % (name, name, age, job, hobby)
# print(msg)
#第二种使用方法
# dic = {
# 'name':'老男孩',
# 'age':58,
# 'job':'boss',
# 'hobby':'money',
# }
# msg = '''
# ------------ info of %(name)s -----------
# Name : %(name)s
# Age : %(age)d
# job : %(job)s
# Hobbie: %(hobby)s
# ------------- end -----------------
# ''' % dic
# print(msg)
# 格式化输出,在格式化输出中,单纯的表示% 需要用%% 去表示。
# msg = '我叫%s,今年%s,学习进度2%%' % ('爽妹儿','18')
# print(msg)

#while else 当while循环被break打断,则不走else程序。
# count = 0
# while count <= 5:
# count += 1
# print("Loop",count)
# if count == 4: break
#
# else:
# print("循环正常执行完啦")
# print("-----out of while loop ------")

5,编码初始

谍战片:嘀嘀嘀 滴滴  高低电平,0101010
电脑文件的存储,与文件的传输 010101010
初级密码本 :ascii 字母,数字,特殊字符。
0000 0001 8位== 1个字节 一个字节表示一个字符。
字符:组成内容的最小单元。 abc a b c
中国 中 国

a 01100001
b 01100010
c 01100011

万国码:unicode
创建初期 16位 两个字节表示一个字符。
a :01100001 01100001
中:01100011 01100001

升级:32位 四个字节表示一个字符。
a :01100001 01100001 01100001 01100001
中:01100011 01100001 01100011 01100001
资源浪费。
对Unicode升级 :utf-8。
utf-8:最少用8位数去表示一个字符。
a:01100001(字母用1个字节表示。)
欧洲文字:01100001 01100001(欧洲用2个字节表示。)
亚洲文字——中:01100001 01100001 01100001 (欧洲用3个字节表示。)
utf-16:最少用16位数去表示一个字符

gbk:国家标准。
a : 01100001
中: 01100001 01100001

8位 1个byte
1024bytes 1kb
1024kb 1MB
1024MB 1GB
1024GB 1TB
原文地址:https://www.cnblogs.com/juxiansheng/p/8963611.html