"""
python简介
python版本:python -V 或 python --version
python特色:
1.python是一种解释性语言:这意味着开发过程中没有编译这个环节。类似于PHP和Perl
2.python是交互式语言:这意味着可以在一个python提示符 >>> 后直接执行代码
3.python是面向对象语言:这意味着python支持面向对象的风格或代码封装在对象的编程技术
4.python是初学者语言:python对初级程序员而言,是一种伟大的语言,它支持广泛的应用程序开发,从简单的文字处理到WWW浏览器再到游戏
python特点:
1.易于学习
2.易于阅读
3.易于维护
4.有广泛的标准库
5.互动模式
6.可移植性
7.可扩展性
8.可嵌入
9.数据库
10.GUI编程
"""
# python3源码文件以UTF-8编码,所有字符串都是unicode字符串
"""
标识符:
1.第一个字符必须是字母表中的字母或下划线_
2.标识符的其他部分由字母,数字,下划线组成
3.标识符对大小写敏感
"""
# python保留字
import keyword
print(keyword.kwlist)
"""
['False', 'None', 'True', '__peg_parser__', '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']
"""
# 多行语句:python通常是一行写完一条语句,但如果语句很长我们可以使用反斜杠 \ 来实现多行语句
total = "item_one," + \
"item_two," + \
"item_three"
print(total) # item_one,item_two,item_three
# 在[],{},()中的多行语句,不需要使用反斜杠 \
total = ["item_one",
"item_two",
"item_three"]
print(total) # ['item_one', 'item_two', 'item_three']
"""
数字Number类型:整数,浮点数,布尔性,负数
"""
"""
字符串String
1.python中单引号 ' 和双引号 " 使用完全相同
2.使用三引号 ''' 或 \""" 可以指定一个多行字符串
3.转义符 \
4.反斜杠可以用来转义,使用 r 可以让反斜杠不发生转义
5.按字面意义及联字符串 如 "this""is""String"会被自动转换为 thisisString
6.字符串可以用 + 运算符链接在一起,用 * 运算符重复
7.python中字符串有两种索引方式,从左往右以 0 开始,从右往左以 -1 开始
8.python中的字符串不能改变
9.python没有单独的字符类型,一个字符就是长度为 1 的字符串
10.字符串的截取的语法格式如下:变量[头下标:尾下标:步长]
"""
str = "this" "is" "String"
print(str) # thisisString
str1 = '字符串'
str2 = "这是一个句子"
str3 = """这是一个段落,
可以由多行组成"""
print(str1)
# 字符串
print(str2)
# 这是一个句子
print(str3)
"""
这是一个段落,
可以由多行组成
"""
str4 = "123456789"
print(str4[::-1])
# 反转:987654321
print(str4[0:2])
# 12
print(str4 + "0")
# 1234567890
print(str4 * 2)
# 123456789123456789
print("\n")
# 输出空行
print(r"\n")
# \n
# print输出
x = "a"
y = "b"
# 换行输出
print(x)
print(y)
"""
a
b
"""
# 不换行输出
print(x, end="")
print(y)
# ab
print(x, y)
# a b
# python3基础语法