Python cha3之前简单回顾
2023.04.06
针对与C的不同点
#####输出函数print
print(520)
print(3.2)
print("hello world")
print(3 + 1)
# 将数据输出文件中,注意点 1、所指定的盘符存在 2、使用 file=
fp = open('D:/python/text.txt', 'a+') # a+ 如果文件不存在就创建,存在就追加
print('hello world', file=fp)
fp.close()
# 不换行
print('hello', 'world', 'python')
#####转义字符
print('hello\nworld') # \n换行
print('hello\tworld') # \t制表长度(4)
print("helloooo\tworld") # 如果\t前面占满4格的倍数,后续新开一个制表长度(4)
print('hellooo\tworld')
print('hello\rworld') # \r回车(回到开头),覆盖了hello
print('hello\bworld') # \b退一格
print('http:\\\\www.baidu.com')
print('老师说:\"大家好\"')
# 不希望字符串中的转义字符起作用,在字符串前加上r/R
# 注意:最后一个字符不能是一个反斜杠
print(R'hello\nworld')
print(r'hello\nworld\\') # 不可以是\
#####python中的标识符和保留字
import keyword
print(keyword.kwlist)
#####变量定义
name = 'ShenGGG'
print(name)
n = id(name) # id表示内存地址
c = type(name) # type表示变量类型
print(n, c)
运行结果`
`