python第二部分

2021-07-09 20:06

阅读:448

标签:reverse   center   翻转   sort   列表   str   验证   remove   .so   

什么数据类型?
int 1, 2, 3 用来运算的
float 1.2

str 用来存储一定的信息"" ‘‘

list =[1,2 ,3 "有", 是]用来存储大量的信息
touple(1,2, 3,) 用来存储不变的列表,只能读

dic ={"我":"金燎源" "你" : "北京"} 用来存储数据关系,方便查找
set = {1, 2, 3, 4} 求集合的差集,并集,交集


#字符串的大写

#字符串的操作

# s = ‘alexWusir‘
# # s1 = s.capitalize()
# # print(s1)
#
# #大写,小写
# s2 = s.upper()
# s3 = s.lower()
#
# print(s2, s3)

# s_str = ‘acEQ‘
#
# your_input = input("请输入验证码,不区分大小写:")
#
# if s_str.lower()== your_input.lower():
# print("输入成功")
# else:
# print("请重新输入")

#大小写翻转
# s = "Alex Wusir"
#
# s3 = s.swapcase()
# print(s3)
#每个隔开的单词首字母大写
# s = "alex wusir"
# s4 = s.title()
# print(s4)
#居中
# s = "alexWusir"
#
# s5 = s.center(20,‘*‘)
# print(s5)

#公共办法
# s = "alex二高"
#
# l = len(s)
# print(l)

#以什么开头
# s = "alexyouaresogood"
# s7 =s.startswith("alex")
# s7 =s.startswith("ex", 2,3)
# print(s7)
#find 可以索引,找不到返回-1
#index通过元素找索引,找不到报错
# s = "alexWusWir"
# s8 = s.index("A")
# print(s8, type(s8))
#rstrip从右边开始删除,lstrip从左边开始删除
# s = "*** Alex wusir %%%"
# s9= s.strip("*% ")
# print(s9)

# s = "alexaa wusrila"
# s10 = s.count("a")
#
# print(s10)


#split 将字符串分割成列表
#
# s = "alexl wusir;lambaba"
# l = s.split("a")
#
# print(l)
#
# s = "我叫{name}, 今年是{age}, 爱好{hobb}, 再说一下我叫{name}".format(name="太白",age=23,hobb="girl")
# print(s)


# s = "来看待街坊邻居街坊的事情"
# s10 = s.replace("街坊","老王",1)
# print(s10)

s = "siidjaijdlakdla"

# for i in s:
# print(i)

s = "fadacandadjik苍井空ksdalks"

# if "苍井空"not in s:
# print("你的评论有敏感词")

# s = "123e2"
# print(float(s))


li = [1,‘a‘,‘b‘,2,3,‘a‘]
# li.insert(0,55) #按照索引去增加
# print(li)

# li.append(‘aaa‘) #增加到最后
# li.append([1,2,3]) #增加到最后
# print(li)

# li.extend([‘q,a,w‘]) #迭代的去增
# li.extend([‘q,a,w‘,‘aaa‘])
# li.extend(‘a‘)
# li.extend(‘abc‘)
# li.extend(‘a,b,c‘)
# print(li)
#
# li.extend([‘q,a,w‘])
# li.extend(‘qwa‘)
# print(li)

li = [1, 2, 3, 4]

# l1 = li.pop(1)
# print(l1)

# del li[1:3]
# print(li)

# li.remove(2)
# print(li)

# li.clear()
# print(li)

#改正
lst = [1, 2, 3, 4, 3]

# lst[1] = "asbd"
# print(lst)
# lst[1:3] = [‘a‘, ‘b‘]
# print(lst)
# a = [1,2,3 ,45,3,3]
# # print(a.count(3))
# print(a.index(3))

a = [1,3,43,45,2,123,34,34]

# s10 = a[5:0:-1]
s10 = a[-1: :-1]
print(s10)
# a.sort(reve
# rse=True)
# print(a)
# a.reverse()
# print(a)

python第二部分

标签:reverse   center   翻转   sort   列表   str   验证   remove   .so   

原文地址:https://www.cnblogs.com/jly1/p/9563911.html


评论


亲,登录后才可以留言!