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')
python 代码片段8的更多相关文章
- Python 代码片段收藏
list 列表相关 list 中最小值.最大值 import operator values = [1, 2, 3, 4, 5] min_index, min_value = min(enumerat ...
- 有用的Python代码片段
我列出的这些有用的Python代码片段,为我节省了大量的时间,并且我希望他们也能为你节省一些时间.大多数的这些片段出自寻找解决方案,查找博客和StackOverflow解决类似问题的答案.下面所有的代 ...
- 2019-01-29 VS Code创建自定义Python代码片段
续前文[日常]Beyond的歌里最多是"唏嘘"吗? - Python分词+词频最后的想法, 发现VS Code支持用户自定义代码片段: Creating your own snip ...
- Python - 代码片段,Snippets,Gist
说明 代码片段来自网上搬运的或者自己写的 华氏温度转摄氏温度 f = float(input('请输入华氏温度: ')) c = (f - 32) / 1.8 print('%.1f华氏度 = %.1 ...
- python 代码片段26
#coding=utf-8 ''' 使用空格而不是tab 因为无论在什么平台上开发,你的代码总是有可能会被移动或是复制到 另一不同架构的机器上,win32是4个空格,unix是8个空格,干脆 还是使用 ...
- python 代码片段25
#coding=utf-8 # 虽然python是面向对象的语言,但是没有显式的构造函数概念. # python没有new关键词 class MyClass(object): pass m=MyCla ...
- python 代码片段23
#coding=utf-8 #python还支持动态的实力属性,即那些没有在类定义里生命的属性, #可以"凭空"创造出来 john.tatto='Mom' #继承 class Em ...
- python 代码片段22
#coding=utf-8 class AddressBookEntry(object): version=0.1 def __init__(self, name,phone): self.name ...
- python 代码片段20
#coding=utf-8 # 函数 def foo(x): print x foo(123) # import httplib def check_web_server(host,port,path ...
- python 代码片段19
#coding=utf-8 # 函数 def foo(x): print x foo(123) # import httplib def check_web_server(host,port,path ...
随机推荐
- SELinux入门
导读 如果你在之前的Linux生涯中都禁用或忽略了SELinux,这篇文章就是专门为你写的:这是一篇对存在于你的Linux桌面或服务器之下的SELinux系统的介绍,它能够限制权限,甚至消除程序或守护 ...
- @version ||= version
# -*- encoding : utf-8 -*- class InterfaceBaseController < ActionController::Base private def set ...
- [POJ1936]All in All
[POJ1936]All in All 试题描述 You have devised a new encryption technique which encodes a message by inse ...
- ZeroMQ(java)之Router与Dealer运行原理
在开始这部分的内容之前,先来看看ZeroMQ中HWM概念---High-Water Marks 当系统的数据量很大,而且发送频率很高的情况下,内存就很重要了,如果处理不好会出现很多问题,例如如下场景: ...
- BestCoder Round #60 1002
Problem Description You are given two numbers NNN and MMM. Every step you can get a new NNN in the w ...
- Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- js获取文本框输入的值
<script type="text/javascript"> function getPosition(obj) { ; if (obj.selectionStart ...
- 如何判断CPU字节序之[Big-endian vs Little-endian]
[本文链接] http://www.cnblogs.com/hellogiser/p/big-endian-vs-little-endian.html [Big-endian vs Little-en ...
- 【转】php json_encode中文为空的解决办法
转自:http://www.cnblogs.com/oldphper/p/4123415.html 本文列举3个方法,实现json_encode()后的string显示中文问题. 做接口时不需要,但存 ...
- C# 支持多种语言
通过Resource文件建立本地化. net 资源文件名(这里是Resource1.resx)由根名称(即Resource1),本地语言名称(默认情况下还没有)及扩展名组成,在读取资源时,资源管理器会 ...