python 代码片段8

#coding=utf-8
# 列表推倒式子
data=[x+1 for x in range(10)]
print data

even_numbers=[x for x in range(10) if x%2 == 0]
print even_numbers

# 字符串
# 字符串是不可修改的,其大小也不能改变。任何试图改变字符串长度获释修改
# 内容的行为实际上是创造了一个心的修改过的字符串而已
print 'this is a string'
print "this is a string"

s='django is cool'
words=s.split()
print words
print ' '.join(words)
print '::'.join(words)
print s.upper()
print s.upper().isupper()
print s.title()
print s.capitalize()
print s.count('o')
print s.find('go')
print s.startswith('python')
print s.replace('django','python')




原文地址:https://www.cnblogs.com/yufenghou/p/5097324.html