python 学习(二) 变量类型

python字符串

eg:
x='hello word'
y="wosai"

字符串列表有两种取值顺序

  1. 从左到右,0到 length-1;
  2. 从右到左,-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)

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值