@Sarah
2016-04-03T14:00:40.000000Z
字数 1665
阅读 867
区分大小写,字幕开头
input = raw_input("Please enter your name")
print input
//function example
def print_lyrics():
print "Im a AAA"
print 'I sleep'
print_lyrics()
//rerurn values
def greet():
return "Hello"
print greet(), "Gleen"
print greet(), "Sally"
//while Loops
n = 5
while n>0:
print b
n = n-1
print 'Blastoff!'
print n
//Breaking out of a loop
n = 5
while True:
print n
if n == 3:
break
//finishing an iteration with continue
n = 5
while n>0:
n=n-1
if n>=3:
continue
print n
//For Loop
for i in [5,4,3,2,1]:
print i
print 'Blastoff'
//if elif else
if x<y:
print 'x is less than y'
elif x>y:
print 'x is greater than y'
else:
print 'x and y are equal'
//try and catch
inp = raw input("Enter Fahrenheit Temperature:')
try:
fahr = float(inp)
cel = (fahr -32.0)*5.0/9.0
print cet
except:
print 'please enter a number'
//Strings
str1 = 'H'
str2 = 'T'
bob = str1 + str2
print bob
str3 = '123'
str3 = int(str3)+1
print str3
//index
fruit = 'b'
x = len(fruit)
print x
for letter in fruit:
print letter
//
s = 'Monday Python'
print s[0:4]
print s[6:7]
print s[6:20]
s ='Monday Python'
print s[:2]
print s[8:]
print s[:]
//true anf false
fruit = 'banana'
'n' in fruit
'm' in fruit
'nan' in fruit
if 'a' in fruit:
print 'Found it!'
//String library
str.capitalize() 首字母大写
str.upper() 全部大写
str.lower()小写
str.find() finds the first occurrence of the substring.没找到的话返回-1
str.replace()
str.lstrip()
str.strip()
str.startswith()搜搜用啥开头的
字符串不能够改变。
list1 = [2,3]
//
range(4)
//
a = [1,2]
b= [3,4]
c = a+b
print c
//
list1.remove(2)
list1.append(2)
//常用列表函数
list.pop()
.reverse()
.sort()
.count()
.index()
.max()
.min()
.sum()
//
purse = dict()
purse['m'] = 12
purse['c']=5
//tuple
d = {'a':10,'b':1,'c':22}
t = d.items()
print t
for k.v in c.items():
temp.append((v,k))
print tmp
c = {'a':10,'b':2,'c':13}
print sorted c
```
```python
import re
x = "wwwwweetjyuketgha34273i5"
y = re.findall('[0-9]',x)
print y
//
import re
x = "From: Using the : character"
//
y = re.findall('\s+@\s',x)