英文不规范,别学我
持续更新中。。
def hello(name):
print("hello, " + name)
def isEmpyt(Test_Name):
if Test_Name:
print('不为空')
else:
print('是空的,因为[],'',()是空序列,{}是空映射')
# 必须是三个不同的数字
def who_most_Big(x, y, c):
bigest = 0
if x > y:
if x > c:
bigest = x
else:
bigest = c
else:
if y > c:
bigest = y
else:
bigest = c
print("最大值是 " + str(bigest))
def changge_cod(num, str):
if num == '1':
str_decode = str.decode('utf-8')
print("把字符变成了Unicode")
print(str_decode)
if num == '2':
str_encode = str.encode('gbk')
print("把Unicode变成了字符")
print(str_encode)
def welcome_str():
print("==连接与重复==")
str1 = "北京"
str2 = "欢迎你"
str_3 = str1 + str2
str_4 = str2 * 2
str_5 = 'str1' + 'str2'
str_6 = '-'.join(['1', '2', '3', '4'])
print(str_3, str_4, str_5, str_6)
print("==格式化==")
# %d 是 数字, %s 是字符串
str_7 = '%s-%s' % ('我', '爱旦旦')
str_8 = '%(name)s-%(toname)s' % {'name': '我爱', 'toname': '我家TT'}
str_9 = '{name}-{toname}'.format(name='旦旦', toname='一点都不爱我')
str_10 = '{0}-{1}'.format('我爱', '我国')
print(str_7, str_8, str_9, str_10)
print("==索引与切片==")
str_11 = str1[0]
str_12 = str1[:]
print(str_11, str_12)
str3 = ' abcd_figel '
print('原本的是' + str3)
print("==查找==")
print(str3.find('cd'), str3.index('g'))
print("==替换==")
print(str3.replace('abcd', 'ABCD'))
print("==裁剪(去前后的空格)==")
print(str3.strip())
print("==分割==")
print('我真的不爱TT'.split('不'))
def welcome_list_tuple():
# 列表可修改, 元组不能修改
list1 = [1, 2, 3]
tuple1, tuple2 = (1, 2), (1,)
list2 = [tuple1]
print(list1, list2, tuple1, tuple2)
list3 = list1 + [4]
list4 = list3[0:2]
list5 = list4.append(5)
list6 = ['我爱TT'] * 2
list7 = [[] for x in range(0, 3)]
print(list3, list4, list5, list6, list7)
del list1[0]
print(list1, len(list3), len(tuple1))
if __name__ == '__main__':
# input_name = input("请输入你的名字: ")
# hello(input_name)
# lista = []
# dicta = {}
# stra = ''
# strb = ' ' # 不为空
# isEmpyt(strb)
# who_most_Big(9, 3, 4)
# print("数据类型与常用的数据结构有: ")
# type_list = {
# '字符串': 'str = "我是字符串"'
#
# }
# changge_cod('1', b'as')
# changge_cod('2', "abdasd")
# print(len(type_list))
# welcome_str()
welcome_list_tuple()