t1 = (1,"Hello",True)
t2 = ()
t3 = tuple()
print(f"t1的数据类型为:{type(t1)}")
print(f"t1的数据类型为:{type(t2)}")
print(f"t1的数据类型为:{type(t3)}")
t4 = ("hello",)
t5 = ((1,2,3),(4,5,6))
t5[1][2]
t6 = ("itheima","itcast","itheima","python")
index = t6.index("itheima")
print(index)
num = t6.count("itheima")
num = len(t6)
index = 0
while index < num:
print(t6[index])
index+=1
for element in t6:
print(element)
t11 = (1,2,["itheima","itcast"])
t11[2][0] = "it"
print(t11)
my_str = 'itheima and itcast'
value = my_str[2]
value2 = my_str[-16]
index = my_str.index("and")
print(index)
my_str = my_str.replace("it","ahahahah")
print(my_str)
my_str = "hello python itheima itcast"
new_my_str = my_str.split(" ")
print(f"将字符串{my_str}进行split切分后得到:{new_my_str},类型是{type(new_my_str)}")
my_str = " itheima and itcast "
print(my_str.strip())
my_str = "12itheima and itcast2121"
print(my_str.strip("12"))
my_list = [0,1,2,3,4,5,6,7]
result = my_list [1:4]
print(result)
my_tuple = (0,1,2,3,4,5,6,7)
result2 = my_tuple[:]
print(result2)
my_str = "0123456789"
result3 = my_str[::2]
print(result3)
my_str = "0123456789"
result4 = my_str[::-1]
print(result4)
my_list = [1,2,3,4,5,6,7]
result5 = my_list[3:1:-1]
print(result5)
my_tuple = (0,1,2,3,4,5,6,6,7)
result6 = my_tuple[::-2]
print(result6)
my_set = {"传智教育","ieheima","黑马程序员","itheima","ieheima","黑马程序员","itheima"}
my_set_empty = {}
print(my_set)
my_set.add("Python")
print(my_set)
my_set.remove("Python")
print(my_set)
result = my_set.pop()
print(result)
my_set.clear()
set1 = {1,2,3}
set2 = {1,5,6}
set3 = set1.difference(set2)
print(set3)
set1.difference_update(set2)
print(set1)
set1 = {1,2,3}
set2 = {1,5,6}
ser3 = set1.union(set2)
print(ser3)
num = len(ser3)
print(num)
for element in set1:
print (element)
my_dict = {"Rookie" : 99,"TheShy":88,"ning":77}
my_dict2 = {}
my_dict3 = dict()
print(my_dict["Rookie"])
stu_score_dict = {
"王力宏":{
"yuwen":66,
"shuxue":88
},
"周杰伦":{
"yuwen":88,
"shuxue":88
},
"林俊杰":{
"yuwen":88,
"shuxue":58
}
}
print(stu_score_dict["周杰伦"]["yuwen"])
print(stu_score_dict["林俊杰"]["yuwen"])
my_dict = {"周杰伦":99,"林俊杰":88,"张学友":77}
my_dict["张信哲"] = 66
print(my_dict)
my_dict["周杰伦"] = 33
print(my_dict)
score = my_dict.pop("周杰伦")
print(my_dict)
print(score)
my_dict.clear()
my_dict = {"周杰伦":99,"林俊杰":88,"张学友":77}
keys = my_dict.keys()
print(keys)
for key in keys:
print(key)
print(my_dict[key])
for key in my_dict:
print(key)
num = len(my_dict)
print(num)
list(my_set)
sorted(my_list)
sorted(my_list,reverse=True)
def test_return():
return 1,"sss",True
x,y,z = test_return()
print(x)
print(y)
print(z)
def user_info(name,age,gender):
print(f"您的名字是:{name},年龄是{age},性别是{gender}")
user_info('小明',20,'男')
user_info(name = '小王',age = 18,gender = '女')
user_info(age = 55,name = '哈哈哈',gender = '男')
def user1_info(name,age,gender = '男'):
print(f"您的名字是:{name},年龄是{age},性别是{gender}")
def user2_info(*args):
print(args)
user2_info(1,2,3,'小明','小白')
def user3_info(**keywords):
print(f"args的参数类型为:type(keywords),内容是:{keywords}")
user3_info(name = '小王',age = '99',gender = '女')
def test_func(computer):
result = computer(1,2)
print(f"computer参数的类型是:{type(computer)}")
print(result)
def computer(x,y):
return x+y
test_func(computer)
def test_func(computer):
result = computer(1,2)
print(result)
test_func(lambda x,y:x+y)
import time
f = open("D:/测试.txt","r",encoding = "UTF-8")
print(type(f))
print(f"读取字节:{f.read()}")
lines = f.readlines()
print(lines)
print(type(lines))
line1 = f.readline()
line2 = f.readline()
line3 = f.readline()
print(line1)
print(line2)
print(line3)
for line in f:
print(line)
f.close()
with open("D:/测试.txt","r",encoding = "UTF-8") as f:
for line in f:
print(f)
f = open("D:/word.txt","r",encoding="UTF-8")
count = 0
for line in f:
line = line.strip()
words = line.split(" ")
print(words)
for word in words:
if word == "itheima":
count += 1
print(count)
f.close()
f = open("D:/he.txt","w",encoding="UTF-8")
f.write("哈哈哈")
f.flush()