好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python基础(一)

版本:Python 3.8.5 print("hello,python!") 集成开发环境:PyCharm 默认情况下,Python 3 源码文件以 UTF-8 编码,所有字符串都是 unicode 字符串 标识符大小写敏感,必须由数字字母下划线组成,不能数字开头,不能是python关键字

import keyword 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']

Python中单行注释以 # 开头 多行注释可以使用三引号 python最具特色的就是使用缩进来表示代码块

如果语句很长,我们可以使用反斜杠()来实现多行语句,但在 [], {}, 或 () 中的多行语句,不需要使用反斜杠() python中数字有四种类型:整数、布尔型、浮点数和复数。 字符串使用单引号或双引号括起来 使用三引号可以指定一个多行字符串 转义字符 \ 原始字符串 r'c:\windows\newfile' 级联字符串 'this' 'is' 'peter' 字符串连接 + 字符串重复 *

字符串索引 hello[开始:结束:步长]

str1 = '0123456789' type(str1) <class 'str'> print(str1) 0123456789 print(str1[0:-1]) 012345678 print(str1[0]) 0 print(str1[2:6]) 2345 print(str1[2:]) 23456789 print(str1[:8]) 01234567 print(str1 + 'number') 0123456789number print(str1 * 2) 01234567890123456789 print('hi',str1) hi 0123456789 print(r'c:\windows\newfile',str1) c:\windows\newfile 0123456789

空行也是程序的一部分 等待用户输入 input() 同一行显示多条语句,分号隔开 print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end="" 导入模块 import 和 from ... import ... 我们在使用脚本形式执行 Python 时,可以接收命令行输入的参数 多个变量赋值 x=y=z=10 a,b,c=1,'two',3.14 python标准数据类型:数字 字符串 列表 元组 集合 字典

name = 'zhangsan' isinstance(name,str) True type(name) <class 'str'>

数值运算 + - * / % ** //

字典(dictionary)是Python中另一个非常有用的内置数据类型 字典当中的元素是通过键来存取的,而不是通过偏移存取 在同一个字典中,键(key)必须是唯一的

查看更多关于python基础(一)的详细内容...

  阅读:19次