python入门练习

英文不规范,别学我

 

持续更新中。。


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()

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一身正气z

打赏随心就好

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值