python 学习(二) 变量类型
python字符串
eg:
x='hello word'
y="wosai"
字符串列表有两种取值顺序
- 从左到右,0到 length-1;
- 从右到左,-1 开始;
x = 'hello word!'
y = "hello word!"
print(x[1:7] + '\n' + y[-7:-2])
print(x[2:])
print(x*2)
print(x + "yeah~")
# 第三个参数为步幅
print(x[1:8:3])
字符串输出
print("My name is %s ,and my age is %s !" % ("Nana", 17))
python 数据类型转换
https://www.runoob.com/python/python-variable-types.html
python 日期和时间
时间
import time
# 获取当前时间:从返回浮点数的时间戳方式向时间元组转换,只要将浮点数传递给如localtime之类的函数
locatime1 = time.localtime(time.time())
print("获取当前时间:\n", locatime1)
print(" 1-7, 1-366,是否夏令时")
# 获取格式化的时间
locatime2 = time.asctime(time.localtime(time.time()))
print("获取格式化的时间: \n", locatime2)
# 格式化日期
print("格式化日期:")
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
a = "Sat Mar 28 22:24:24 2016"
print(time.mktime(time.strptime(a, "%a %b %d %H:%M:%S %Y")))
日期
import calendar
cal = calendar.month(2020, 7)
print("输出七月月历:\n", cal)