一、day01

1.二进制运算

  60 & 13  =12

  60 |  13  =61

  60 ^ 13  =49

  60<<2   =240

  60>>2   =15

2.逻辑运算符

  and   or  not

3.关系运算符

  in  not in

4.验证运算符

  is  is not

5.字符编码

    ASCII只用了8bit,即1byte只能表示255个字符,对于欧美足够用.但是其它非英语国家的语言文字不能包括,比如中国就制定gb2312,各国都有自己的标准。

   因此unicode出现,可以包括所有国家编码文字,通常2bytes,特殊时需要4bytes.

   最后utf-8本着节约精神,结合了ascii 和unicode,属于可变长编码,也是是我们大家常用的。

   ascii->unicode->utf-8

   注意:在计算机内存中,统一使用unicode,当需要保存到硬盘或者传输时,就转换成utf-8.      

        当用记事本编辑的时候,从文件读取的 UTF-8 字符被转换为 Unicode 字符到内存里,编辑完 成后,保存的时候再把 Unicode 转换为 UTF-8 保存到文件.
        ascii-->GB2312-->GB18030-->GBK-->unicode-->UTF8可变长

  Python的ascii转换执令:

    >>> ord('A') 

    65

    >>> chr(65) 

    'A'

  python2.7中可以使用

    >>> u'abc'.encode('utf-8')    #unicode --> utf-8

    'abc'

    >>> 'abc'.decode('utf-8')      #utf-8 --> unicode

    u'abc'

  python3.x中则统一使用unicode,加不加u都一样,只有以字节形式表示字符串则必须前面加b, 即b"abc"

    >>>a='tom'  

    >>>a.encode('utf-8')

    b'tom'

    >>> a='中国'

    >>> a

    '中国'

    >>> a.encode('utf-8')

    b'\xe4\xb8\xad\xe5\x9b\xbd'

6.list列表(python的精随)

  nameList=['tom','apple','cat','tom']

  dir(nameList)

  nameList.append('tom')

  nameList.index('tom')

  nameList.count('tom')

  nameList.remove('tom')

  nameList.sort()

  nameList.reverse()

  nameList.pop()

  nameList.insert(2,'tom')

  nameList.clear()

  namelist[:]

  nameList.extend(otherList)

  if 'tom' in nameList:

    print('ok')

  for i in range(nameList.count('tom')):

      nameList.remove('tom')

7.交互

1 # -*- coding:utf8 -*-
2 import getpass
3 name=input("What is your name?")
4 pwd=getpass.getpass("What is your passwd?")

8.for loop

 for i in range(10):
print("loop:", i ) for i in range(10):
if i<5:
continue #不往下走了,直接进入下一次loop
print("loop:", i ) for i in range(10):
if i>5:
break #不往下走了,直接跳出整个loop
print("loop:", i )

9.while loop

 count = 0
while True:
print("你",count)
count +=1
 count = 0
while True:
print("你是风儿我是沙,缠缠绵绵到天涯...",count)
count +=1
if count == 100:
print("去你妈的风和沙,你们这些脱了裤子是人,穿上裤子是鬼的臭男人..")
break

10.猜年龄

 #!/usr/bin/env python
# -*- coding: utf-8 -*- my_age = 28 count = 0
while count < 3:
user_input = int(input("input your guess num:")) if user_input == my_age:
print("Congratulations, you got it !")
break
elif user_input < my_age:
print("Oops,think bigger!")
else:
print("think smaller!")
count += 1 #每次loop 计数器+1
else:
print("猜这么多次都不对,你个笨蛋.")

11.三元运算

a=10
result = 10 if a=10 else 20
#如果a=10,则result=10,否则result=20

最新文章

  1. NSLogger 简单用法总结
  2. CSS2中基本属性的介绍
  3. SVM算法入门
  4. 51NOD 1623 完美消除 数位DP
  5. SQL集合函数中利用case when then 技巧
  6. php可变变量
  7. iOS中FMDB的使用【单例】
  8. Centos yum源更新为阿里云
  9. 一篇非常经典的springMVC注解实现方式详解
  10. (原)测试intel的并行计算pafor
  11. PHP入门-摘要表格处理问题
  12. django 5 form1
  13. 首届.NET Core开源峰会
  14. JS对象2
  15. js获取地址栏中的数据
  16. ByteToByte64String、Base64StringToBytes
  17. STL_map.VC6简单使用例子
  18. 小程序-wepy学习
  19. (笔记)CanOpen协议【CanFestival】移植方法 支持VC、QT、STM32
  20. 如何在windows上测试iphone?

热门文章

  1. uboot中断功能实现
  2. 宝宝书 &amp; 网站
  3. MPAndroidChart -- LimitLine的坑
  4. Tensorflow之计算tensor平均值
  5. css !import
  6. Alpha matting算法发展
  7. CentOS下搭建LNMP+WordPress+http2.0教程
  8. SharePoint服务器端对象模型 完结
  9. POJ 2609 Ferry Loading(双塔DP)
  10. ZOJ 3941 Kpop Music Party(省赛, 贪心)