admin管理员组

文章数量:1622541

a= []

b = [1,'c','abd',851,[1,2,3]]
#列表中元素的修改
b[0] = "HELLO"
b[4]= 23
#去除列表中的元素,通过索引
# for i in range(len(b)):
#     print(b[i])


#遍历
for item in b:
    print(item)

#成员运算符 in
if 6 in b:
    print("success")
else:
    print("not in")

#更新列表
list_1 = [1,2,3]
#使用append方法,为列表添加元素,每次添加都添加到最后一位
for i in range(100):
    list_1.add(i)

print("b=",list_1)

#删除列表中的元素
del list_1[2]
print(list_1)

# #列表相加
list_2 = [4,5,6]
list_3 = list_1+list_2
print(list_3)

#对列表进行切片操作
list_4 = ["芝麻","花生","巧克力","花生","转世","西瓜"]

#list_4[n:m],n=<X<N=import
print(list_4[2:5])

#统计列表的长度 len
print(len(list_4))
#获取列表中最大的元素
list_5 = [1,58,78,99,289]
print(max(list_5))
print(min(list_5))

#counter方法 快速统计列表中的每个元素出现的次数
string1=""
list_6=string1.split("In the flood of darkness, hope is the light. It brings comfort, faith, and confidence. It gives us guidance when we are lost, and gives support when we are afraid. And the moment we give up hope, we give up our lives. The world we live in is disintegrating into a place of malice and hatred, where we need hope and find it harder. In this world of fear, hope to find better, but easier said than done, the more meaningful life of faith will make life meaningful.")

#用counter方法统计每个单词出现的次数
from  collections import  Counter
print(Counter(list_6))



# 元组与列表的区别,元组的值不能改变
typle_1=["1","6","zhang",3,8,[1,2]]
typle_1[1]=8
print(typle_1)

# 字符串
tring_1="hello world"
tring_2='hello world 2' \
        '666666'
string_3="""i am a boy 
hello world
yes i am
"""

# 统计字符串的长度len(),空格也在统计范围之内
print(len(string_3))

# 通过加号添加两个字符串
string_4=string_3+tring_1
print(len(string_4))

# 字符串的复制,通过*来复制
tring_3=tring_1*100
print(tring_3)

#字符串的转换str()来实现
number = 5
string_7= str(number)
print(type(string_7))

# 字符串的提取
string_8 = "cat.jpg"
print(string_8[3:7])

#字符串的替换,replace(_'旧字符串',"新字符串")
string_9= "hello <h1>world</h2><em><span>!"
string_10= string_9.replace('h1',"").replace('/h2',"").replace('em',"").replace('span',"")
print(string_10)

# 统计高频词汇。用split方法
string_11="""2021年12月大学英语四级考试真题(第1套)
Part I Writing (30minutes)
Directions: Suppose your school is organizing an orientation program to help the freshmen
adapt to the new environment and academic studies. You are now to write a proposal, which
may include its aim, duration, participants and activities. You will have 30 minutes to write the
proposal. You should write at least llQ words but no more than 1Jj_Q words.
Part II
Section A
Listening Comprehension (25 minutes)
Directions: In this section, you will hear three news reports. At the end of each news report,
you will hear two or three questions. Both the news report and the questions will be spoken only
once. After you hear a question, you must choose the best answer from the four choices marked
A), B), C) and D). Then mark the corresponding letter on Answer Sheet 1 with a single line
through the centre.
Questions 1 and 2 are based on the news report you have just heard.
1. A) It found a pet dog on board a plane to a city in Texas.
B) It had one of its cargo planes land at a wrong airport.
C) It sent two dogs to the wrong destinations.
D) It had two of its domestic flights mixed up.
2. A) Correct their mistake as soon as possible.
B) Give the two pets a physical checkup
C) Hire a charter jet to bring the pets back
D) Send another plane to continue the flight.
Questions 3 and 4 are based on the news report you have just heard.
3. A) She weighs 130 kilograms
B) She has had babies before.
4. A) It took 22 hours.
B) It had some complications.
C) She was brought from Africa.
D) She has a big family of six
C) It was smooth.
D) It was monitored by Dr.Sue Tygielski
Questions 5 to 7 are based on the news report you have just heard.
5. A) It enjoyed great popularity C) It was frequented by newly-weds.
B) It started business three years ago. D) It was built above the sea-water.
6. A) Expand his business on the beach.
B) Replace the restaurant's wooden deck.
C) Post a picture of his restaurant online.
D) Celebrate his silver wedding anniversary.
2021 年 12 月英语四级真题第 1 套 第 1 页共 10 页 by: UVOOC.COM微信公众号:AMYOU
7. A) She sold it for two thousand dollars. C) She posted its picture on Facebook.
B) She took it to the restaurant manager. D) She returned it to its owner right away.
Section B
Directions: I

本文标签: 字符串知识列表Python