作业一

  2-1 简单消息:将一条消息存储到变量中,再将其打印出来。
         str="bigelow"

        print (str)
  2-2 多条简单消息:将一条消息存储到变量中,将其打印出来;再将变量的值修改为一条新消息,并将其打印出来。

        str="bigelow"
        print(str)
        str="change"
        print(str)
 2-3 将用户姓名存在一个变量,并向该用户显示一条信息。

        name=input()
        str="Hello "+name+", would you like to learn some Python today?"
        print(str)
2-4 调整名字的大小写:将一个人名字存储到一个变量中,再以小写、大写和首字母大写的方式显示这个人命

        name=input()
        print(name.title())                    #首字母大写
        print(name.upper())                #大写
        print(name.lower())                #小写
2-5 名言:打出一句名人名言

        print('Maxim Gorky said, "When work is a pleasurem, life is joy! When work is duty, life is slavery."')
2-6 名言2:
        famous_people="Maxim Gorky"
        famous_words="'When work is a pleasure, life is joy! When work is duty, life is slavery.'"
        sum=famous_people+" said, "+famous_words
        print(sum)
2-7 删除人命中的空白:存储一个人命,删除左右的空白
       word="    \thello world\n"
       print(word.strip())        #显示"hello world"
       print(word.rstrip())       #显示"       hello world"
       print(word.lstrip())        #显示"hello world↓"

2-8 输出4个表达式,它们的结果都是8
       print(3+5)
       print(10-2)
       print(1*8)
       print(int(16/2))   #python3中整数相除也会显示浮点数,所以要用Int  
2-9 选择一个数字,放入字符串中,并找到其位置
       found=2
       str1="blaaaaaaa"+str(found)+"blilililili"
       import re              #此处引入正则表达式式模块,其中的函数可以方便地查找到目标字符的位置
       re.search(str(found),str1).start()        #start为search函数中的子函数,可以显示查找到的字符串的首地址
结果:9
2-10 添加注释

        单行注释:#
        多行注释:'''   注释  '''
2-11 python之禅

import this 召唤神龙!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值