day 04
一、Typora介绍
- 第一标题 快捷键:Ctrl+1 不用快捷键则是用#,有几个#就是第几标题
- 第二标题 快捷键:Ctrl+2 以此类推
- 第一标题的子目录 :*+空格
- 标题下的子目录的子目录:*+空格+Tab
- 若要在子目录的子目录的前提下返回字母录按:enter
- Ctrl+?可看到源代码
- 写Python的话按:```(英文状态下的情况下按)
二、上周内容回顾
-
变量与常量
#变量的定义 #由 变量名 + 赋值符号 + 变量值 组成 #例: name = 'ycc' #变量名命名的规范: #1.由字母数字下划线组成 #2.开头不能为数字 #3.尽量不要用下划线:_ #4.不要与关键字冲突:'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from','global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield'] #要做到见名知意 #变量名的命名风格 #1.下划线式(python推荐) #user_name、user_password #2.驼峰体(js推荐使用) #大驼峰体:UserName、UserPassword #小驼峰体:userName、userPassword #python 中没有严格意义上的常量,默认使用全大写的变量名作为常量 #全大写的变量名主要用在配置文件中 #ps:在其他语言中有真正的常量 -
垃圾回收机制
引用计数 标记清除 分代回收 -
Python基本数据类型
#整型int: age = 18 #浮点型float: salary = 15.8 #字符串str: #引号引起来的部分 描述文本 name = 'ycc' #列表list #表现形式:中括号括起来,内部可存放多个元素,元素与元素之间逗号隔开,元素可为任意数据类型 l = ['qq', 'eee', ['aa', 122]] #字典dict #表现形式:大括号括起来,内部可存放多个元素,元素变现形式k:v键对值,k一般为描述V值的描述信息, #v可以是任意数据类型 dict1 = {'name':'ycc', 'age':27, } #bool值 True 、False ''' 当变量名存储的值为bool值得情况下 那么变量名一般为is开头,例: is_delete is_right is_status '''
三、今日内容概要
-
用户交互
#1.定义:与程序实现沟通交流 #2.输入: # input()在python2与python中是有区别的 ''' #python3中: res = input('please input your name>>>:') print(res, type(res)) #id返回一串数字(可看成内存地址但是注意不是内存地址),这边输出的type为:str。 #ps:在python3中input输出的任意类型皆为str ''' ''' #python2中: 需要自己人为指定其数据类型 ps:在python2中的 raw_input 等价于python3中的 input ''' #3.输出: print: #先写print print('ycc') #先写待打印的内容 'ycc'.print # 按tab键即可 -
格式化输出
user_name = input('请输入您的用户名') user_password = input('请输入您的密码') #1. %s ,定义:是一个占位值,后续传值替换即可 #格式: print('my name is %s my password is %s'%('ycc', 1217)) # 按顺序 print('my name is %(name)s my password is %(password)s'%{'password':1217, 'name':'ycc'})#可不按顺序 # %d 也是一个占位符 但是只能给数字占位 #例:print('my name is %s my password is %d'%('ycc', 1217)) #print('%08d'123) 输出结果:00000123 补全8位 print('%08d'123123123) 输出结果:123123123 已经超过8位 #2. str.format 兼容性好 #格式: print('my name is {} my age is {}'.format('ycc', 27)) # 按照位置传值 #输出结果:my name is ycc my age is 27 print('my name is {0}{0}{0} my age is {1}{1}'.format('ycc',27)) #输出结果:my name is yccyccycc my age is 2727 print('my name is {name} my age is {age}'.format(age=27, name=ycc'))#可打破位置限制 #输出结果:my name is ycc my age is 27 #3. f'' python3.5以后才能使用 inp_username = input('my name is :') inp_userpassword = input('my password is :') res = f'my name is {inp_username} my password is {inp_userpassword}' print(res) 输出结果是: #input后自己输入name password my name is ycc my password is 1217 -
基本运算符
#赋值运算符 name = 'ycc' #算数运算符 + - * / // 取整 % 取余 ** 幂指数 print(1 - 1) print(1 * 10) print(10 / 2) print(10 // 3) # ===》3 print(10 % 3) # ===》1 print(2 ** 4) # ===》16 #python语言对数字的精确度并不是很高,需要借助'大佬'的辅助 #其他的数据类型也可以使用局部的数学运算符 print('ycc'+' call it a day') ===>ycc call it a day print('ycc'*2) ===>yccycc #增量赋值 x = 1 x = x + 1 # 等价于 x += 1 #链式赋值 x = 10 y = x z = x #以上三行代码等价于 : x = y = z = 10 #交叉赋值 x = 10 y = 12 #需求:是x,y的值互换 #方法一: x = temp x = y y = temp print(x, y) #方法二: x, y = y, x print(x, y) #解压赋值 # 方法一: name_list = ['ycc', 'xixi', 'aaa', 'Tracy'] name1 = name_list[0] name2 = name_list[1] name3 = name_list[2] name4 = name_list[3] print(name1, name2, name3, name4) # 方法二: name_list = ['ycc', 'xixi', 'aaa', 'Tracy'] name1, name2, name3, name4 = name_list print(name1, name2, name3, name4) # 快速解压前几个值或者后几个值:*_ l = [11, 33, 44, 55, 66, 77, 88, 99] a, b, *_, c =l # *_ 表示接受到的数据无需使用 print(a, b, _, c) # 输出结果:11 33 [44, 55, 66, 77, 88] 99 print(a, b, c) # 输出结果:11 33 99 print(a, b, _) # 输出结果:11 33 [44, 55, 66, 77, 88] #比较运算符: <、 >、 <=、 >=、 ==、 != print(10 > 2) print(2 == 2) print(3 != 4) #补充: print('hello' > 'world') # 输出结果:False 只需判断第一个字母内部对应数字的大小 h < w ''' 字母内部对应着数字 A-Z:65-90 a-z:97-122 ''' #逻辑运算符 #与 and #或 or #非 not #优先级 not > and > or #bool值为:Fales :0, None , '', {}, [] (重要)

浙公网安备 33010602011771号