python学习笔记之codecademy

1.str的函数

String methods

lower()小写

upper()大写

str()将目标转化为str输出

2.print("a " + "b " + " c") = a b c

3.

name = raw_input("What is your name?")
quest = raw_input("What is your quest?")
color = raw_input("What is your favorite color?")

print "Ah, so your name is %s, your quest is %s, " \
"and your favorite color is %s." % (name, quest, color)

用%s来获得%中的对象,每句之后都要跟着%(),按顺序来。

4.获取时间

from datetime import datetime #导入包
now = datetime.now()


5.

  1. not is evaluated first;
  2. and is evaluated next;
  3. or is evaluated last.
6.python

中的IF需要加冒号的,如if(a>b) :

7.

name = raw_input("What is your name?")

用来打出What is your name?并且接受输入赋给name

8.用from xx import *来导入xx中的全部variable和function

9.my_list = [1,9,3,8,5,7]

for number in my_list:#这种用法第一次见

10.


Write a function called censor that takes two strings, text and word, as input. It should return the text with the word you chose replaced with asterisks.

For example:

censor("this hack is wack hack", "hack") 

should return

"this **** is wack ****"
  1. Assume your input strings won't contain punctuation or upper case letters.
  2. The number of asterisks you put should correspond to the number of letters in the censored word.


def censor(text,word):
    new = text.split()
    for num in range(len(new)):
        if(new[num] == word):
            new[num] = "*" * len(word)
    return " ".join(new)

说明:

split()函数,string的split()函数,将sting中通过()中的划分,如(how . are .you).split(.) = ["how","are","you"]

join函数,按照分割符连接起来,如" ".join(new)就是将new这个list的元素中通过" "连接起来




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值