python_day1(初始Python)
1.编码
ASCII (英文1字节,没中文)=> GB => GBK
=>uncoode (中英文都2字节)
=> utf-8 (可变长字节储存,中文3字节,英文1字节)
2.第一个程序
hello world
3.输密码
#Author:Elson Zeng
import getpass _username = 'jian' _passwd = '123' username = input("username:") passwd = input("passwd:") if _passwd == passwd and _username == username: print ('welcome user {name} login'.format(name=username)) else: print ('Invalid username or passwd!')
4.while and for 循环
#Author:Elson Zeng
age_of_oldboy = 56 count = 0 for i in range(3): guess_age = int(input('guess age:')) if guess_age == age_of_oldboy: print ('you guess ture!') exit() elif guess_age > age_of_oldboy: print ('you guess big') else: print ("you guess small") count += 1 else: print('you guess too many times,fuck off~!')
5.认识模块
#Author:Elson Zeng import sys # print(sys.path) # print(sys.argv) # print(sys.argv[1]) import os #cmd_res = os.system("dir") cmd_res = os.popen("dir").read() print ("--",cmd_res) os.mkdir("new_dir")
6.内置函数
bin() 十进制转二进制
any() 判断真假
bool() 判断真假
chr() 返回asill码
ord() 返回asill对应的字符
dict() 生成字典
dir() 查看方法
divmod() 除商返回余数
eval () 字符串变列表
filer () 过滤函数
res = filter(lambda n:n>5,range(10)) for i in res: print(i)
import functools res = functools.reduce(lambda x,y : x+y,range (10)) print (res) """ 45 """
frozenset() 不可变列表
globals() 返回程序里所有的变量以字典形式返回
haxi() 折半算法+
len() 长度
next()
oct() 变八进制
range()
round() 保留小数
sort() 排序
type() 类型
zip() 一一对应
a = [1,2,3,4] b = ['a','b','b'] for i in zip(a,b): print (i)
__import__() 寻找模块的字符串