pyhon函数传参的时候穿的是引用,而不是实际值,这样可以节省内存

变量名要求:最好是以字母下划线作为变量名,不能和py关键字重复

import getpass提供了平台无关的在命令行下输入密码的方法(pycharm无法使用),可隐藏密码显示。

两个函数:1.getpass.getpass() :可带提示符, 不带提示符,则会输入默认提示符'Password: '   2.getpasss.getuser():该函数返回登陆的用户名,不需要参数

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码

 

循环

1、单分支
    if   条件:
      满足条件执行
  2、多分支
    if   条件1:
      满足条件1执行
    elif  条件2:
      满足条件2执行
    ......支持多个elif
    else:
      都不满足执行
  while 条件:
  # 循环体
   # 如果条件为真,那么循环体则执行
   # 如果条件为假,那么循环体不执行  可以设置个变量,将变量赋值为真(a=True),通过在循环内,改变变量的真假,控制循环
  如果在循环的过程中,因为某些原因,你不想继续循环了,怎么把它中止掉呢?这就用到break 或 continue 语句
• break用于完全结束一个循环,跳出循环体执行循环后面的语句
• continue和break有点类似,区别在于continue只是终止本次循环,不循环continue之后的代码啊,接着还执行下次后面的循环,break则完全终止循环
 for
  while是在条件为真的情况下,一直循环,for是在固定次数中循环

While,For循环

python 字节转换gb代码 python字符转换字节_开发工具_02

python 字节转换gb代码 python字符转换字节_开发工具_03

Break:结束当前本次循环

Continue:跳出本次循环,进入下一次循环

python 字节转换gb代码 python字符转换字节_ico_04

python 字节转换gb代码 python字符转换字节_开发工具_05

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码_06

python 字节转换gb代码 python字符转换字节_开发工具_07


_age_zhangchao=30
count = 0
#while True:
while count<4:
    if count == 4:
        break
    age_age = int(input('age_age:'))
    if age_age==_age_zhangchao:
        print('ok')
        break
    elif age_age> _age_zhangchao:
        print('输入年龄过大')
    else:
        print('输入年龄过小')
    count +=1
    if count == 3:
        count_=input('你要继续吗')
        if count_ !='n':
            count = 0
else :
    print('错误')

 

作业: 

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,        用户登录(三次机会重试)

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码_08

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码_09

python 字节转换gb代码 python字符转换字节_ico_10

计算机基础知识:

bit是计算机能识别的最小单位

8 bit=1Byte=1字节=255=2^8-1

字节是计算机中存储的最小单位

1024Byte=1KByte=1KB

1024KByte=1MByte=1MB 100万字节

1024MB=1GB=10亿字节

1024GB=1TB=1万亿字节

硬盘是外部存储:1.数据断电不丢失,2.可重复读写,3.速度慢(相对于内存)硬盘转速越快读写速度越高

固态硬盘:价格贵,速度快,连续读写速度都是300MB/S以上

Utf-8编码:一个汉字3个字节。Gbk编码:一个汉字2个字节。一个字节=8位(01010101)

String/Bytes转换

 

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码_11

msg = '我爱北京天安门'
print(type(msg))
print(msg.encode(encoding='utf-8'))#将字符类型转换为bytes
print(msg.encode(encoding='utf-8').decode(encoding='utf-8'))#将bytes类型转换为字符

  

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码_12

python 字节转换gb代码 python字符转换字节_python 字节转换gb代码_13

python 字节转换gb代码 python字符转换字节_python_14

Py3.5:里面for 循环每个元素都是字符,如:len(‘张超’)长度2

Py2.7:里面for 循环每个元素都是字节,如:len(‘张超’)长度6

python 字节转换gb代码 python字符转换字节_开发工具_15

字符编码转换

python 字节转换gb代码 python字符转换字节_ico_16


Encode编码, decode解码
import sys
print(sys.getdefaultencoding())#打印当前使用的编码格式


python 字节转换gb代码 python字符转换字节_开发工具_17


s_gbk=s.encode('gbk')
print(s_gbk)
print(s.encode())

gbk_to_utf8=s_gbk.decode('gbk').encode('utf-8')#gbk转回utf8
print('utf8',gbk_to_utf8)

s='你好'
print(s.encode('gbk'))
print(s.encode('utf-8'))
print(s.encode('utf-8').decode('utf-8').encode('gb2312').decode('gb2312'))#最终转换为字符串
python2编码转换
s='你好'#utf-8编码
s_to_unicode=s.decode('utf-8')#utf8先转到unicode
print(s_to_unicode)
s_to_gbk=s_to_unicode.encode('gbk')#unicode转到gbk
print(s_to_gbk)

gbk_to_utf8=s_to_gbk.decode('gbk').encode('utf-8')#gbk转回utf8,转之前要告诉自己之前是gbk才行
print(gbk_to_utf8)