Python初步使用教程

1.基本输出print函数
python 复制代码
a=10
b=20
print(a)#输出结束后会自动换行
print(b)
print(a,b,'猪猪侠')#print中sep决定三者之间会存在空格

#连接方法一
print('猪猪',end='')
print('侠')
#连接方法二(只能是字符串和字符串连)
print('超级'+'无敌')

print(chr(67))
print(ord('猪'))

fp=open('note.text','w')#打开文件 w-->write
print('超级棒棒糖',file=fp)#将"超级棒棒糖"写入note.txt文件中
fp.close()#关闭文件
2.基本输入input函数

无论用户输入的是数字还是字符串,input统一按照字符串处理

若需要输出整型,则通过int转换

python 复制代码
name=input('请输入你的幸运数字是:')
name=int(name)
print('我的幸运数字是:',name)
3.注释

单行注释快捷键:Ctrl+/

python 复制代码
#单行注释
'''
多行
注释
'''

第三种中文声明注释了解即可

4.变量与常量

Python是一种动态类型语言,变量的类型可以随时变化

相关推荐
花酒锄作田4 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪8 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽8 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战9 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋15 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama