Python
2022-02-10 14:45:12 0 举报
AI智能生成
登录查看完整内容
Python的基础语义
作者其他创作
大纲/内容
https://www.python.org/
安装后的目录
IDE设置python的模板
安装
以#开头
单行注释
''' 多行注释多行注释'''
使用一对 ''' 三个单引号
多行注释
# coding:utf-8
中文编码声明
注释类型
变量定义,内存中的保存形式
float类型
例如:print(0) 输出为False,除上述情况外,都是True
布尔类型
int、float、布尔、str
name='王五'age=20# int转为stringprint('我是:'+ name + \";今年\"+str(age)+\"岁!\")
类型转换str()、int()、float()
# 转义字符print('hello\world')print('hello\\tworld')print('helloooo\\tworld') # \\t 四位一个制表符,满4位重开,不满四位补足print('hello\world') # \ 回到头不输出后面的内容print('hello\\bworld') # \\b 是退一个格,将o删除了print('http:\\\\\\\\www.baidu.com')print('you say:\\'hello\\'')
转义字符
键盘输入
输入值为str
如要转换,需用类型转换,如 int(input(\"第一个数字:\"))
input函数
函数
数据类型
子主题
# money = 1000# s = int(input(\"请输入取款金额:\"))# if money>s:# money=money-s# print(\"余额:\
print( 1 if 1<2 else 2 )
if
b=1sum2=0while b<=100: if not bool(b%2): # if b%2==0: bool(0) == false sum2+=b b+=1print(sum2)
while
range
print('-------------for------------------')for item in 'hel': print(item)for item in range(3): print(item)for _ in range(3): print(\"循环次数\") breakprint('-------------for-else-----------------')for item in range(3): if item > 4: print(\"测试1\") break else: print(\"测试2\
for
结构
列表
字典
元组
集合
列表、字典、元组、集合
驻留机制
字符串
异常处理
class Student_demo: passprint(\"一切皆对象\
类
实例对象创建的内存流程
print(\"-------支持多继承---------\
继承
模块
with语句(上下文管理器)
文件操作
输出的内容中有生成的exe的位置,如果需要使用还需要将相关资源拷贝到exe的同级目录下
打包
Python
0 条评论
回复 删除
下一页