基础知识(一)
1.编码
默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串。
2.保留字
import keyword
keyword.kwlist # 查看保留字
3.输出print 默认输出是换行的,如果要实现不换行需要在变量末尾加上end="":
print(x, end="")
4.import与from...import在 python 用 import 或者 from...import 来导入相应的模块:
将整个模块导入:
import name_module
从整个模块中导入函数:
from name_module import func1, func2
5.多个变量赋值
a, b, c = 1, 2, 'hello'
6.标准数据类型
Python3 有6个标准数据类型:
Number, String, List, Tuple, Sets, Dictionary
用 isinstance来判断 Number类型(type()):
>>> a = 120
>>> isinstance(a, int)
True
1) List[ ]
列表中元素的类型可以不相同,它支持数字、字符串,甚至可以包含列表(嵌套)
list1 = ['asd', 234, ['fgh']]
list1[0] = 't'