摘要: Python中列表索引和切片 # 创建一个混合列表 my_list = [1, 1.0, '1ab', True, [1, 1.0, '1'], {1}, {1: 1.0}] print('列表长度为') print(len(my_list)) # 列表长度为 # 7 # 打印每个元素和对应的序号 阅读全文
posted @ 2024-07-16 17:09 像一棵海草海草海草 阅读(2) 评论(0) 推荐(0) 编辑
摘要: Python中常用f-string用法 import datetime now = datetime.datetime.now() print(f'{now:%Y-%m-%d %H:%M}') print(f'{now:%d/%m/%y %H:%M:%S}') # 2023-10-02 06:11 阅读全文
posted @ 2024-07-16 17:09 像一棵海草海草海草 阅读(4) 评论(0) 推荐(0) 编辑
摘要: Python中常用占位符类型 'The first letter of Python is %c' % 'P' # 'The first letter of Python is P' 'Welcome to the world of %s!' % 'Python' # 'Welcome to the 阅读全文
posted @ 2024-07-16 17:08 像一棵海草海草海草 阅读(2) 评论(0) 推荐(0) 编辑
摘要: Python中将数据插入字符串 name = 'James' height = 181.18 # 使用 + 运算符 str_1 = name + ' has a height of ' + str(height) + ' cm.' print(str_1) # James has a height 阅读全文
posted @ 2024-07-16 17:08 像一棵海草海草海草 阅读(4) 评论(0) 推荐(0) 编辑
摘要: Python中字符串索引和切片 greeting_str = 'Hey, James!' # 打印字符串长度 print('字符串的长度为:') print(len(greeting_str)) # 字符串的长度为: # 11 # 打印每个字符和对应的索引 for index, char in en 阅读全文
posted @ 2024-07-16 13:22 像一棵海草海草海草 阅读(6) 评论(0) 推荐(0) 编辑
摘要: Python中字符串的定义和操作 str1 = 'I am learning Python 101!' print(str1) # I am learning Python 101! str2 = "Python is fun. Machine learning is fun too." print 阅读全文
posted @ 2024-07-16 13:10 像一棵海草海草海草 阅读(5) 评论(0) 推荐(0) 编辑
摘要: Python中的三类数组 x = 88 # 整数 y = -8.88 # 浮点数 z = 8 + 8j # 复数 print(type(x)) print(type(y)) print(type(z)) 阅读全文
posted @ 2024-07-16 12:48 像一棵海草海草海草 阅读(2) 评论(0) 推荐(0) 编辑