python中竞赛题常用用法,还在扩充中hh

# 把文本型数字转换成数字
x = "2023"
num = 0
for i in range(len(x)):
    # 从前往后加,这个2最后是x1000了的
    num = num * 10 + int(x[i])
print(num)


# 得到数字中的每一位数
x = 2023
while x:
    t = x % 10  # t是个位的数
    x //= 10    # 把个位数去掉
    if t == 2:
        print(t)


# https://blog.csdn.net/qq_39293334/article/details/126375616
# 字符串逆序
# 1.for循环
# 2.字符串切片
str0 = '1234'
str1 = str[::-1]
# 3.用列表的reverse
tmp = list(str0)
tmp.reverse()
str2 = ''.join(tmp)


# 将列表转换成字符串['4', '3', '2', '1'] -->'4321'
b = ''.join(['4', '3', '2', '1'])


# 给的数据中间没空格时要找其中某个数
r = 5       # 行数
a = [[0] * 100 for _ in range(100)]
for i in range(r):
    j = 0
    for tmp in input():
        a[i][j] = tmp
        if tmp == 'S':  # 找出字符串S和E
            start = (i, j)
        if tmp == 'E':
            end = (i, j)
        j += 1


# 定义二维数组
a = [[0] * 100 for _ in range(100)]


# 迷宫问题之类的往上下左右走
dxy = [(1, 0), (0, 1), (-1, 0), (0, -1)]
tmp = (0, 0)
for i in dxy:
    x, y = tmp[0] + i[0], tmp[1] + i[1]


# 自带库中的日期库
from datetime import *

a = datetime(2023, 1, 4)
b = datetime(2045, 4, 3)
# https://blog.csdn.net/Changxing_J/article/details/129491976
# 日期格式化成字符串
tmp = a.strftime("%m%d%Y")
print(tmp)
# 输出结果01042023
# 字符串按格式搞成日期
tmp = "20230123"
c = datetime.strptime(tmp, "%Y%m%d")
print(c)
# 结果2023-01-23 00:00:00
c += timedelta(days=1)
print(c)
# https://blog.csdn.net/weixin_45914452/article/details/124745960
# 遍历日期
while c <= b:
    c += timedelta(days=1)
print(c)
# /是除法有小数位 5 / 2 = 2.5
# //是向下整除   5 // 2 = 2
# %是取余       5 % 2 = 3

# sorted是不改变数组值的
# sort是改变值的

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值