# 把文本型数字转换成数字
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是改变值的