1.执行Python脚本时打印的字符有颜色

 print  "\033[32;1mhello\033[0m"  #打印绿色
print "\033[31;1mhello\033[0m" #打印红色

2.time 模块的使用

 b = time.time()  #打印当前时间的时间戳
print b
c = time.localtime() #打印元组形式的当前时间
print c
d = time.strftime("%Y-%m-%d %H:%M:%S",c) #把元组形式的时间转化为格式化的时间
print d

3.字符串常用方法

 mag = "hello wlllllord"
print mag.capitalize() #字符串的首字母大写
print mag.center(30,"@") #字母居中,30是长度,@号为两边的填充符号
print mag.count("l",0,9) #计算这个字符串中l的总数,
print mag.endswith("o") #判断o是否是这个字符串的结尾,如果是返回True,如果不是返回False
print mag.isalnum() #判断这个字符串是不是个数字,返回true或false
print mag.isdigit() #判断这个字符串是不是个数字,返回true或false
print mag.isupper() #判断这个字符串是不是大写,返回true或false
print mag.islower() #判断这个字符串是不是小写,返回true或false
print mag.upper() #变成大写字母
print mag.lower() #变成大写字母
print mag.ljust(30,"!") #“hello wlllllord!!!!!!!!!!!!!!!”
print mag.rjust(30,"*") #***************hello wlllllord
print mag.strip() #去除空格
mag1 = "hhhhhhhhhh\nhhhhhhhhhh"
print mag1.split() # 效果 ['hhhhhhhhhh', 'hhhhhhhhhh']
names.pop()                               #删除列表最后一个值
names.remove("Eric")                       #删除指定元素
names.extend(b)                              #把b列表和names列表合并

4.列表

 list = ["aa","bb","ee","cc","dd","dd"]
#list.extend("ww") #往列表中添加2个元素w
#list.index("bb") #返回这个元素的索引值
#list.count("dd") #求这个元素的数量
#list.append("xx") #追加一个元素
#list.reverse() #顺序反一下
#list.insert(1,"qq") #在索引1前边插入一个元素
#list.remove("aa") #删除元素aa
#list.sort() #排序

5.三级菜单练习

 # -*- coding:utf-8 -*-
import paramiko,os,sys,time
data = {
"美国":{
"纽约":"aaaaaaaaaa",
"芝加哥":"zhijiagedajuyuan",
"华盛顿":"baigong"
},
"中国":{
"北京":{
"朝阳":"qunzhong",
"海淀":"中关村"
},
"上海":"东方明珠",
"西安":"兵马俑"
},
"日本":{
"东京":{
"冲绳":"垃圾"
},
"广岛":{
"核电站":["危险","小心"]
},
"横滨":"横滨大桥"
}
} while True:
for i in data:
print i
choice = raw_input("选择进入》")
if choice in data:
while True:
for i2 in data[choice]:
print i2
choice2 = raw_input("选择进入》")
if choice2 in data[choice]:
while True:
for i3 in data[choice][choice2]:
print i3
choice3 = raw_input("选择进入》")
if choice3 in data[choice][choice2]:
while True:
for i4 in data[choice][choice2][choice3]:
print i4
choice4 = raw_input("最后一层了,按b返回上一层,按q退出")
if choice4 == "b":
break
elif choice4 == "q":
exit()
if choice3 == "b":
break
elif choice3 == "q":
exit()
if choice2 == "b":
break
elif choice2 == "q":
exit()
elif choice == "q":
exit()

Python学习之day2的更多相关文章

  1. Python学习日记 --day2

    Python学习日记 --day2 1.格式化输出:% s d  (%为占位符 s为字符串类型 d为数字类型) name = input('请输入姓名') age = int(input('请输入年龄 ...

  2. python学习(day2)

    1.常用数据类型及内置方法 1.列表(list) 定义:在中括号[]内存放任意多个值,用逗号隔开. 具体函数和内置方法如下: #定义学生列表,可存放多个学生 students=['a','b','c' ...

  3. Python学习笔记 - day2 - PyCharm的基本使用

    什么是IDE 开始学习的小白同学,一看到这三个字母应该是懵逼的,那么我们一点一点来说. 既然学习Python语言我们就需要写代码,那么代码写在哪里呢? 在记事本里写 在word文档里写 在sublim ...

  4. Python学习第二阶段Day2,模块time/datetime、random、os、sys、shutil

    1.Time.  Datetime(常用) UTC时间:为世界标准时间,时区为0的时间 北京时间,UTC+8东八区 import time print(time.time()) # timestamp ...

  5. Python学习路程day2

    import sys      #接收执行参数 #!/usr/bin/env python import sys print (sys.argv)​ 例: >>>python ind ...

  6. Python学习笔记——Day2

    一.集成开发环境 集成开发环境(IDE,Integrated development Enviroment)是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器.调试器和图形用户界面等工具.集 ...

  7. [python学习笔记]Day2

    摘要: 对象 对于python来说,一切事物都是对象,对象基于类创建: 注:查看对象相关成员 var,type,dir 基本数据类型和序列 int内部功能 class int(object): def ...

  8. python学习笔记-Day2 Numpy数组

    1. 实现两个数组相加,在数据量特别大的时候 产生数组: (1)  从列表产生数组:a=[0,1,2,3] a=np.array(1) a (2)  从列表传入 a=np.array([1,2,3,4 ...

  9. Python学习第二阶段Day2,模块subprocess、 logging、re

    1.logging 日志开关,设置全局只打印什么级别的日子,默认是warning以下的都不打印 改默认级别:依次升高 logging.debug("") logging.info( ...

随机推荐

  1. iOS之应用发布中的一些细节

    Bundle identifier Xcode中 Target -> General中的bundle identifier ; info.plist中的Bundle identifier; 证书 ...

  2. Android UI:ListView -- SimpleAdapter

    SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便. layout : <?xml version="1.0" encoding=&qu ...

  3. LruCache缓存

    LruCache通常用于实现内存缓存,采用的缓存算法是LRU(Least Recently Used)即近期最少使用算法,其核心思想是:当缓存满的时候,会优先淘汰那些近期最少使用的缓存对象. 1.Lr ...

  4. IOS开发之Bug--遇到一个类型不确定的bug

    下面的问题不大,是我在开发中遇到的问题: 然后我就google搜一下这个报错 . 下面就解决了:

  5. ORA-00600: internal error code, arguments: [17281], [1001], [0x1FF863EE8], [], [], [], [], []

    我们生产服务器中的一个数据库发出监控告警日志的邮件,内容如下所示,在31号09:11分出现了大名鼎鼎的ORA-00600错误. Dear All: The Instance xxx' alert lo ...

  6. Asp.Net MVC+BootStrap+EF6.0实现简单的用户角色权限管理3

    首先在webconfig中加入下面这句代码,这个主要是用来生成数据库的连接字符串 <connectionStrings> <add name="AuthorDesignCo ...

  7. AD设置板子原点

  8. 详解Linux命令行下常用svn命令

    1.Linux命令行下将文件checkout到本地目录 svn checkout path(path是服务器上的目录) 例如:svn checkout svn://192.168.1.1/pro/do ...

  9. Neutron 理解(14):Neutron ML2 + Linux bridge + VxLAN 组网

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

  10. 【2016-11-6】【坚持学习】【Day21】【主窗口关闭时,同步关闭它的子窗口】

    本来想用委托实现的.但是又觉得没有必要. 方法如下: public MainWindow() { InitializeComponent(); this.Closing += MainWindow_C ...