###########window路径写法##########

In [1]: winpath = 'C:\tmp'

In [2]: print winpath
C: mp In [3]: winpath = 'C:\\tmp' #\t 会变成空格,所以需要加一个'\',转义符号 In [4]: winpath
Out[4]: 'C:\\tmp' In [5]: print winpath
C:\tmp In [6]: wpath = r'C:\tmp' #或者加'r' In [7]: print wpath
C:\tmp

##################内建函数####################

In [11]: hi = 'hello world'

In [12]: hi.capitalize()               #句首的单词首字母大写
Out[12]: 'Hello world' In [13]: hi.title() #报纸的标题,每个单子首字母大写
Out[13]: 'Hello World' In [14]: hi.center(20) #居中 ,不够的用空格补上
Out[14]: ' hello world ' In [15]: hi.center(20,'+')
Out[15]: '++++hello world+++++' In [16]: hi.ljust(20) #左对齐
Out[16]: 'hello world       ' In [17]: hi.ljust(20,'#')
Out[17]: 'hello world#########' In [18]: hi.rjust(20) #右对齐
Out[18]: '      hello world' In [19]: hi.rjust(20,'#')
Out[19]: '#########hello world' In [20]: hi.count('l') ####统计出现的次数,‘l’ 出现3次 Out[20]: 3 In [21]: hi.count('ll') ####统计出现的次数,‘ll’ 出现1次
Out[21]: 1 In [22]: hi = 'hello world!' In [25]: hi.startswith('h') #########判断以什么开头,正确返回true,错误返回false
Out[25]: True In [26]: hi.startswith('hello')
Out[26]: True In [23]: hi.endswith('!') #########判断以什么结尾,正确返回true,错误返回false
Out[23]: True
##########比较重要的#############

In [42]: hi = '  hello   world   '   

In [46]: hi.strip().split()      #strip() 去除字符串左右两边的空格,split() 什么都不加,默认以空格为分隔符
Out[46]: ['hello', 'world'] In [47]: mylist = ['hello', 'world'] In [48]: '.'.join(mylist) ###有切割,就有拼接
Out[48]: 'hello.world' In [49]: '/'.join(mylist)
Out[49]: 'hello/world' In [50]: ''.join(mylist)
Out[50]: 'helloworld' In [51]: '\t'.join(mylist)
Out[51]: 'hello\tworld' In [52]: ' '.join(mylist)
Out[52]: 'hello world' In [53]: ' '.join(mylist)
Out[53]: 'hello world'

###########查看方式具体用法##############

In [54]: hi.
hi.capitalize hi.endswith hi.isalnum hi.istitle hi.lstrip hi.rjust hi.splitlines hi.translate
hi.center hi.expandtabs hi.isalpha hi.isupper hi.partition hi.rpartition hi.startswith hi.upper
hi.count hi.find hi.isdigit hi.join hi.replace hi.rsplit hi.strip hi.zfill
hi.decode hi.format hi.islower hi.ljust hi.rfind hi.rstrip hi.swapcase
hi.encode hi.index hi.isspace hi.lower hi.rindex hi.split hi.title In [54]: hi.
hi.capitalize hi.endswith hi.isalnum hi.istitle hi.lstrip hi.rjust hi.splitlines hi.translate
hi.center hi.expandtabs hi.isalpha hi.isupper hi.partition hi.rpartition hi.startswith hi.upper
hi.count hi.find hi.isdigit hi.join hi.replace hi.rsplit hi.strip hi.zfill
hi.decode hi.format hi.islower hi.ljust hi.rfind hi.rstrip hi.swapcase
hi.encode hi.index hi.isspace hi.lower hi.rindex hi.split hi.title In [54]: help(hi.format)
Help on built-in function format: format(...)
S.format(*args, **kwargs) -> string In [55]: help(hi.replace)
Help on built-in function replace: replace(...)
S.replace(old, new[, count]) -> string Return a copy of string S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.

######字符串讲完了,现在开始列表(list)###############

1.list赋值与更新

In [56]: alist = [10,20,30,40]

In [57]: alist[1:3]
Out[57]: [20, 30]

In [58]: alist[1:3] = [2,3]

In [59]: alist
Out[59]: [10, 2, 3, 40]

[root@master script]# vim stack.py
#!/usr/bin/python
# coding:utf-8 stack = [] def pushit():
item = raw_input('item:')
stack.append(item)
def popit():
stack.pop() def viewit():
print stack def show_menu():
CMDs = {'':pushit,'':popit,'':viewit} ###这个方法很好用
prompt = """(0) push it
(1) pop it
(2) view it
(3) quit
Please input your choice(0/1/2/3):""" while True:
choice = raw_input(prompt).strip()[0]
if choice not in '':
print 'Invalid input,Try again'
continue
if choice == '':
break
"""
elif choice == '0':
pushit()
elif choice == '1':
popit()
elif choice == '2':
viewit()
"""
CMDs[choice]() #字典型函数调用 if __name__ == '__main__':
show_menu()

最新文章

  1. js简单操作Cookie
  2. ahk之路:利用ahk在window7下实现窗口置顶
  3. AngularJS时间轴指令
  4. C# DllImport用法和路径问题
  5. HTML无序列表和有序列表
  6. 【java基础学习】泛型
  7. C语言中的 extern 关键字
  8. 已禁用对分布式事务管理器(MSDTC)的网络访问。请使用组件服务管理工具启用 DTC 以便在 MSDTC 安全配置中进行网络访问。
  9. Spring 3 + Quartz 1.8.6 Scheduler Example--reference
  10. Theano学习笔记(二)——逻辑回归函数解析
  11. Installation LEK Cluster
  12. httpd常用配置
  13. [转载] Rss 与 Feed 的概念区别
  14. 当安全遇到java
  15. Java面试题详解一:面向对象三大特性
  16. 解决composer出错的原因
  17. mysql 远程登录
  18. spring batch批量处理框架
  19. ThinkPHP执行原生的SQL语句
  20. Alpha版本项目展示要求(加入模板)

热门文章

  1. SocketIO总结
  2. PHP中的$_SERVER['PATH_INFO']
  3. bluedroid源代码分析之ACL包发送和接收(一)
  4. 这6种思维,学会了你就打败了95%文案!zz
  5. tree related problems (update continuously)
  6. ok6410[001] Ubuntu 16.04[64bit]嵌入式交叉编译环境arm-linux-gcc搭建过程图解
  7. Integrate NSX into Neutron
  8. 微信小程序首页index.js获取不到app.js中动态设置的globalData的原因以及解决方法
  9. 为什么在 Java 中用 (low+high)>>>1 代替 (low+high)/2 或 (low+high)>>1 来计算平均值呢?好在哪里?
  10. python中if __name__ == '__main__': 的解析(转载)