Files
python/练习与案例/序列切片实践.py
2025-08-05 09:19:34 +08:00

20 lines
654 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 序列的切片实践
my_str = "万过薪月,员序程马黑来,nohtyp学"
# 字符串整体倒序,切片取出
result1 = my_str[::-1][9:14]
print(f"{result1}")
# 切片取出,然后倒叙
result2 = my_str[5:10][::-1]
print(f"{result2}")
# split分割”,” replace替换“来”为空,倒叙字符串
result3 = my_str.split("")[1].replace("", "")[::-1]# 写入为中文, 替换也需要为中文,
print(f"{result3}")
# new_my_list = ""
# index = 0
# while index < len(my_list):
# element = my_list[index]
# index += 1
# new_my_list.extend(element)
# new_my_list.extend(f"{my_list[::-1]}")
# print(f"{new_my_list}")