静态网站设计模板,宁夏固原建设网站,django做视频网站,学校网站开发必要性与意义python 的语法逻辑完全靠缩进#xff0c;建议缩进 4 个空格。 如果是顶级代码#xff0c;那么必须顶格书写#xff0c;哪怕只有一个空格也会有语法错误。 下面示例中#xff0c;满足 if 条件要输出两行内容#xff0c;这两行内容必须都缩进#xff0c;而且具有相同的缩进…python 的语法逻辑完全靠缩进建议缩进 4 个空格。 如果是顶级代码那么必须顶格书写哪怕只有一个空格也会有语法错误。 下面示例中满足 if 条件要输出两行内容这两行内容必须都缩进而且具有相同的缩进级别。
if 3 0:print(OK)print(yes) print 函数
print(hello world!)
print(hello, world!) # 逗号自动添加默认的分隔符空格 hello world!
print(hello world!) # 加号表示字符拼接 helloworld!
print(hello, world, sep***) # 单词间用***分隔 hello***world
print(# * 50) # *号表示重复 50 遍
print(how are you?, end) # 默认 print 会打印回车end表示不要回车input
number input(请输入数字) # input 用于获取键盘输入
print(number)
print(type(number)) # input 获得的数据是字符型print(number 10) # 报错不能把字符和数字做运算
print(int(number) 10) # int 可将字符串 10 转换成数字 10
print(number str(10)) # str 将 10 转换为字符串后实现字符串拼接python 中单双引号没有区别表示一样的含义 字符串
py_str python
len(py_str) # 取长度
py_str[0] # 第一个字符
python[0]
py_str[-1] # ⭐⭐最后一个字符
# py_str[6] # 错误下标超出范围
py_str[2:4] # 切片起始下标包含结束下标不包含
py_str[2:] # 从下标为 2 的字符取到结尾
py_str[:2] # 从开头取到下标是 2 之前的字符
py_str[:] # 取全部
py_str[::2] # 步长值为 2默认是 1
py_str[1::2] # 取出 yhn
py_str[::-1] # 步长为负表示自右向左取py_str is good # 简单的拼接到一起
py_str * 3 # 把字符串重复 3 遍t in py_str # True
th in py_str # True
to in py_str # False
to not in py_str # True