1 Star 0 Fork 1

路文超/农大

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
认识python.py 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
路文超 提交于 2024-03-28 06:47 . 第一次作业提交3.28 14:48
name="王sir"
age=18
print(name)
score=10
print(type(score))
height=17.4
print(type(height))
e=1+2j
print(e.real)#获取实数部分:浮点数
print(e.image)#获取虚数部分
print(type(e))
flag=True
print(type(flag))
#字符串 str
say="""我就说一句话"""
print(type(say))
#需求:输出两个变量
uname="中国"
print('你好',uname)
#3.标识符:给变量、函数、类命名
# 特点:见名知意、大小写敏感、不与关键字冲突
# username | user_name
#4.字符串的拓展 url地址--拼串
#4.1 拼串 字符串存字符串 可以 ' ""'
url='https://www.baidu.com/?src="font"'
print(url)
#4.2 字符串格式化:可以将变量和表达式嵌入字符串
#语法:f"字符串{变量名}" f-string
name="露丝"
address="黄岛"
print(f"我是{name},我来自{address}")
#4.3 字符串使用方法: 方法与函数:实现功能
py="我爱python爬虫"
#len方法:获取字符串长度【个数,从1开始】
#方法与遍历一同使用
print(len(py))
#index()方法:返回第一个字符匹配的索引
#特点:获取字符串【元组、列表】等索引位置
print(py.index("python"))
#index("单字符",目标索引)方法:指定索引位置向右查找字符索引位置
py="我爱pythonp爬虫"
print(py.index("p",2))
#strip()方法:默认去掉前后空格
py=" 我爱python爬虫 ".strip("我")
print(py)
print(py.strip().strip("我"))
#爬虫用法:前后有空格,美化数据显示效果
#<htlm></htlm>
#<ol></ol>
#upper|lower用法:改大小写
#用法:同一验证
py="sdDq" #验证码
print(py.upper())
print(py.lower())
print(py.title()) #title()标题方法:首字符大写
#find()方法:获取字符串中字符串的下标索引位置
py="我爱 python 爬虫".find("o")
print(f"find方法效果:{py}")
#join()方法:关联字符串 爬虫输出:拼接,显示结果
a1="/"
a1.join(py) #拼接 返回值
print(f"join方法效果:{py}")
#列表 网络爬虫用法:列表转化为字符
list= ["我是","谁啊"]
print(f"列表输出:{list}")
#拼串
print("".join(list))
#replace(旧字符串,新字符串)方法:
#替换子字符串效果
print("我是张子凡".replace("张子凡","凡尔赛"))
#rsplit()方法:从右侧进行截取字符串,分割列表效果
print("好戏就要开始了".rsplit("就"))
#split()方法:从左侧进行截取字符串,分割列表效果
print("好戏就要开始了".split("戏"))
len("hellopython")
"hellopython".index("o")
"hellopython".index(5,"o")
str="helloPython"
print("".join(str.split("Python")))
str.split("Python")
#--------input()函数、int()函数
#需求:控制台输入文字,判断类型、转换数值
name=input("请输入文字:") #输入数据:字符串
print(f"您输入:{name},判断类"
f"型{type(name)},"
f"转换数值{type(int(name))}")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mayun092521/agricultural-university.git
[email protected]:mayun092521/agricultural-university.git
mayun092521
agricultural-university
农大
master

搜索帮助