栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python笔记一

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python笔记一

字符串学习---------- input交互输入----------
name = input( 'please enter your name:' )print (name)
---------- input 交互输入计算----------
value1 = 1024 * 512value2 = input('num1:')value3 = input('num2:')print (value1)print (value2)print (value3)print (value1 * value2)print (value1 * value3)#当value2 * value3的时候不能如上表示
---------- in 判断变量/值中包含的字符串----------
s = "Wind and cloud"weather1 = "Wind" in sweather2 = "SB" in sprint (weather1)print (weather2)
---------- 变量元组 ----------
Wind = "weather1"Paul = "name"Rain = "weather2"_Coll_1 = ['Wind','Paul','Rain']print(_Coll_1)_Cont_1 = "Wind" in _Coll_1print (_Cont_1)
---------- type 查看对象的类,一般字符串都是标准输入----------
temp1 = "123"_123_io = type(temp1)print(_123_io)temp2 = "hey"_hey_io = type(temp2)print(_hey_io)
---------- dir 查看功能----------
temp = "wind"print(dir(temp))
---------- upper 小写转换成大写----------
temp = "wind"print(temp.upper())
---------- count 字符串统计一定要在一对引号之内的字符串----------
_name_coll = ("paul,vencent,sunny,anny,should,bilibili,david,paul")_coll = _name_coll.count("nn")print(_coll)
---------- endswith 字符串尾部输出定义----------
temp = "hello"print(temp.endswith('e',0,2))    #字符串的0-2的字符he,是以e结尾,python中如果从字符串开头查找字符,必须从0位开始
---------- center 占位输出----------
a1 = "alex"a2 = a1.center(20,'*')print(a2)#字符总数20个,以alex为中心,两边以*号填充
---------- count 统计指定字符串数量----------
a1 = "alex is alpa"a2 = a1.count('al',5,12)print(a2)
---------- expandtabs 分隔符设计20位----------
content = "hellot123"print(content)print(content.expandtabs())print(content.expandtabs(20))
---------- find 字符串位数查找
s = "alex hello"print(s.find("h"))print(s.find("p"))#找不到的字符,会显示负数
---------- str 字符串标准输出,字符串位置输出定义
str = 'Runoob'print  (str[0:3])print (str[0])print (str[2:5])print (str[2:])print (str * 2)print (str + "TEST")
---------- n 本身是换行符,r将字符串中特殊字符转化为普通字符
print('Runnoob')print(r'Runnoob')
---------- format 占位替换,有序排列
x = "hello {0}, age {1}"print(x)y = x.format("paul","27")print(y)
---------- join
alex = "name1"should = "name2"paul = "name3"dio = "name5"name = [alex ,should ,paul ,dio]_name_join = "".join(name)print(_name_join)#将值变成一个整体字符串输出,如果不用元组,只是字符串,可以使用双引号把字符串引起来,加入空格,是字符串相互隔开。name = "alex ","should ","paul ","dio "print (name)_name_join = "".join(name)print(_name_join)
---------- replace 替换字符串
x = "alex is alex"y = x.replace("al","AA")print(y)
---------- split 对字符串进行切片分隔
x = "alexnalex"y = x.split()print(y)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/224729.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号