先将 utf-8 转为 unicode , 再编码为 gbk (本身敲代码)python
#!/usr/bin/env python # -*- coding:utf-8 -*- temp = "测试" #先解码,再编码 temp_unicode = temp.decode('utf-8') temp_gbk = temp_unicode.encode('gbk') print(temp_gbk)
没有了 unicode ,无需本身考虑函数
#直接print()便可 temp = '测试' print(temp)
自动将 unicode 编成 gbk 格式,因此只须要解码为 unicode 便可,以下测试
# -*- coding:utf-8 -*- temp = "测试" temp_unicode = temp.decode('utf-8') print(temp_unicode)
1. 注释 或 取消注释:选中代码 按 ctrl + / 编码
2. 设置 在 File -> settings... 中code
pycharm 修改默认模版对象
File -> settings -> Editor -> Code style -> File and Code templates -> Python Scriptblog
3. ctrl + 鼠标左键 点击关键字,方法名 能够进入定义的位置ip
1) 成员运算符(还有 算术,比较,逻辑,成员,身份 运算符)utf-8
in not in unicode
2) 查看某个对象的类,方法等详细信息
type() dir() help() ctrl + 鼠标左键
val = 'alex' print(type(val)) #查看类名 print(dir(val)) #查看所有方法名 help(type(val)) #超级详细
3) int 类
bit_length() 二进制表示的最短位数
n1+n2 ---> n1__add__(n2)
str 类
li = ['hello', 'world', 'AHA'] s = "###".join(li) print(s) #运行结果为 hello###world###AHA
4) 若源码中函数括号里是 function(self) 表示不用传递参数;若 function(self, asdf, asfd), 表示传递两个参数; 若 function(self, asdf, asfd=None), 表示能够传递一个参数,asfd参数取默认值,固然也能够指定全部参数。