python 简介及环境配置
1.python 是一种解释型语言,在开发过程中没有编译这个环节,这是与Java的区别。而C语言是编译型语言,没有解释这个环节。
2.python和Java都是面向对象语言,C语言是面向过程语言。
3.python环境设置:编辑时显示想要显示的文字
4.设置python快捷键:
print输出
# 教育机构 舒寒科技有限公司
# 学习者 舒寒拽少
# 学习时间: 2022/1/3 17:04
print("helloworld")
print('helloworld')
print(3+1)
#将数据输出到想要的文件中
fp=open('C:/Users/Administrator.SC-202010191845/PycharmProjects/text.txt', 'a+')
#a是创建文件,如果文件存在就追加,不存在就创建。
print('helloworld',file=fp)
fp.close()
#如果运行两次,则txt文件里有两个helloworld,因为a+表示追加,每次执行会重新在里面写东西。
转义字符
# 教育机构 舒寒科技有限公司
# 学习者 舒寒拽少
# 学习时间: 2022/1/3 17:35
#转义字符
print('hello\nworld') #/n为换行
print('hello\tworld') #/t 是空一个tab
print('helloooo\tworld')#如果输出的刚好我四个,则空格为4,如果为3,就空一个。
print('hello\rworld') #\r是回车的意思,会将hello覆盖掉了
print('hello\bworld') #\b是退一个格,将o退没了
print('http:\\\\www.baidu.com')
print('老师说:\'大家好\'')
#原字符:不希望字符串中的转义字符起作用,就使用原字符,就是在字符串之前加上r或R
print(r'hello\nworld')
#注意事项:最后一个字符不能是\,两个就可以
#print(r'hello\nworld\')
print(r'hello\nworld\\')
运行结果:
hello
world
hello world
helloooo world
world
hellworld
http:\\www.baidu.com
老师说:'大家好'
hello\nworld
hello\nworld\\
标识符
输出python中的关键字:
import keyword
print(keyword.kwlist)
运行结果:['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', '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']
标识符规则:
1.以字母,数字,下划线组成
2.不能以数字开头。
3.不能为关键字
4.大小写严格区分