Python 字符串和元组类型的常规操作总结

@1-Python 字符串类型的常规操作总结如下

 

 

 

@2-Python 元组类型的常规操作总结如下:

 

 

@3-字符串相关的操作和运行结果:

import keyword
import random

import pytest
@pytest.fixture(params=[1,2])
def init(request):
ownershipTypeList = [1,2,4,8]
chargeModeList = [1,2,3]
str_1 = 'hello 8888'
str_2 = str_1.replace('8888','9999')
str_3 = '中国加油 中国加油 中国加油 中国加油 88888 9999'
str_4 =str_3.replace('中国加油','China Come on',2)
print('第一种方法')
str_5 = str_1[::-1]
print('第二种方法')
str_6 = list(str_1)
str_6.reverse()
d = {'name1': 'a', 'name2': 'b', 'name3': 'c', 'name4': 'd'}


print("替换前的字符串",str_1)
print("替换后的字符串",str_2)
print("替换前的字符串",str_3)
print("替换后的字符串",str_4)
print("第一种倒序排列的字符串",str_5)
print("第二种倒序排列的字符串",''.join(str_6))
print("字典显示",'@'.join(d.values()))
print("字典显示",'@'.join(d.keys()))
print("随机数01:",random.choice(ownershipTypeList))
print("随机数03:",random.choice([1,2,4,8]))
print("随机数02:",random.choice(chargeModeList))
print("用例名称:", request.function)
print("fix参数 ", request.param)
print("fix的作用域 ", request.scope)
print("用例所在的类 ", request.cls)

@pytest.fixture()
def reverse_zifuchuan():
str_1 = 'hhhhh kkkk gggg'
c = len(str_1) - 1
str_7 = []
while (c > 0):
str_7.append(str_1[c])
c -= 1
print('第三种倒序排列后的字符串', ''.join(str_7))


@pytest.mark.usefixtures("init")
# @pytest.mark.usefixtures("reverse_zifuchuan")
class TestABC:
def test_hello(self):
print("-------------------------")
print(keyword.kwlist)

运行结果:

 


@4-字符串相关的操作和运行结果:
tuple_1 = (2,)
print("元组d第一种赋值:",tuple_1)

data = 1,2,4
tuple_2 = (data)
print("元组d第二种赋值:",tuple_2)
运行结果;

 

posted @ 2022-04-18 16:13  明天有盼望  阅读(56)  评论(0编辑  收藏  举报