什么是转义字符
就是反斜杠 想要实现的转义功能首字母
为什么需要转义字符
当字符中包含反斜杠、单引号和双引号等有特殊用途的字符时 必须使用反斜杠对这些字符进行转义 转换一个含义
反斜杠
单引号 ’
双引号 ’’
当字符串中包含换行、回车、水平制表符或退格等无法直接表示的特殊字符时 也可以使用转义字符。
换行 n
回车 r
水平制表符 t
退格 b
# 开发时间 2021/9/27 16:10 print( hellonworld ) #n换行 print( hellotworld ) #t是表明一组包含四个空格的表格 print( hellootworld ) #t什么时候会出现不同的间隔大小 在占满四个格大小后会重新占据四个格 print( helloootworld ) print( hellooootworld ) print( hellobworld ) #运行后发现少一位 因为会退一格 print( hellorworld ) #运行后会只剩下world 因为r表示会换行 print( http:\www.baidu.com ) print( http:\\www.baidu.com ) #print( 老师说 大家好 ) #报错 print( 老师说 大家好 ) #原字符 不希望字符串中的转义字符起作用 就需要在字符串前面加入r或R print(R hellonworld ) print(r hellonworld ) #注意事项,字符串最后一个不可以“单独的反斜杠” #print( helloworld ) print( helloworld\ )标识符和保留字
保留字 有一些单词被赋予了特定的含义 在给任何对象起名字的时候 都不可以使用。如何查找这些单词
import keyword print(keyword.kwlist) #标识符和保留字
标识符 变量、函数、类、模块和其它对象的起的名字
规则
变量由三部分组成
标示 表示对象所储存的内存地址 使用内置函数id obj 来获取类型 表示的是对象的数据类型 使用内置函数type obj 来获取值 表示对象所储存的具体数据 使用print obj 可以将值打印输出# 开发时间 2021/9/27 17:27 name 233 print(name) print( 标识 ,id(name)) print( 类型 ,type(name)) print( 值 ,name)



