1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| # 1.变量的介绍 a = 1 a = 'ww' a = 3.14 a = True
# type(a) 查看数据类型 # 常用数据类型:int、str、float,bool、list、tuple、dict、set
# 2.变量名的命名规则 # 由字母、数字、下划线组成,不能以数字开头 # 小驼峰: myName = 'ww' # 大驼峰: MyName = 'ww' # 下划线: my_name = 'ww' # (推荐)
# 3.公共运算符 # + 拼接列表,元祖,字符串 # * 复制列表,元祖,字符串
a = [1, 2] b = [3, 4] c = a + b # [1, 2, 3, 4] d = a*2 # [1, 2, 1, 2]
# 4.关键字 # 具有特殊功能的关键字,不能作为函数名和变量名 ''' 变量名: ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] '''
import keyword kw = keyword.kwlist print(kw)
# 5.注释 # 单行注释 ''' 多行注释 '''
# 快捷键:command + /
# 6.数据类型的转换 # str 转 int int(str)
# str 转 float float(str)
# int 转 str str(int)
int + float = float
# 7.输入和输出 # print默认会换行 print('ww') a = 'hello' b = 'world' print(a, b) # hello world print(a, b, sep=",") # hello,world
# 8.global的使用 global表示内存地址发生改变 num = 1 def show(): global num num = 2 show() print(num)
my_list = [1,2] def show(): my_list.append(3) show() print(my_list)
|