摘要: 元组 内置数据结构之一,是一个不可变序列,用()表示。 元组的创建 直接使用() t = (10, 20, 30, 40) print(t) print(type(t)) #### (10, 20, 30, 40) <class 'tuple'> 使用内置函数tuple() t1 = tuple(( 阅读全文
posted @ 2021-02-02 19:35 sxhyyq 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 什么是字典 内置的数据结构,以键值对的方式存储数据,是一个无序的可变序列,用{ }表示。 key不可以重复,value可以重复 scores = {"张三": 100, "李四": 98, "王五": 65} print(scores) print(type(scores)) #### {'张三': 阅读全文
posted @ 2021-01-31 16:03 sxhyyq 阅读(53) 评论(0) 推荐(0) 编辑
摘要: 修改列表的元素 修改列表中的单个元素 l = [10, 20, 'xyq', 'p', 10] l[1] = 's' print(l) #### [10, 's', 'xyq', 'p', 10] 修改列表的多个元素 l = [10, 20, 'xyq', 'p', 10] l[1:3] = [30 阅读全文
posted @ 2021-01-30 21:21 sxhyyq 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 列表 列表的创建: 使用中括号[] list = ['hello', 'world', 123, 3.14] print(list) #### ['hello', 'world', 123, 3.14] 使用函数list() 函数中的参数必须是可迭代对象 list1 = list(range(3)) 阅读全文
posted @ 2021-01-30 20:38 sxhyyq 阅读(43) 评论(0) 推荐(0) 编辑
摘要: 条件表达式 相当于c/c++中的三目运算符__?__:__ 在python中语法是___if ___ else ___ 比如输出两个数中较大数: a = int(input('请输入第一个整数: ')) b = int(input('请输入第二个整数: ')) if a >= b: print(a) 阅读全文
posted @ 2021-01-26 19:39 sxhyyq 阅读(42) 评论(0) 推荐(0) 编辑
摘要: input函数 接收来自用户的输入,输入的类型都是str [variable] = input([提示语]) name = input('What\'s your name? ') print('My name is ', name) #### What's your name? zs My nam 阅读全文
posted @ 2021-01-26 14:59 sxhyyq 阅读(62) 评论(0) 推荐(0) 编辑
摘要: print函数的用法 输出字符串或数字 print([string])或者print([number]) 输出到文件中 fp = open("out.txt","a+") # 以追加模式打开 print([something],file=fp) fp.close() 转义字符: \n \t \r \ 阅读全文
posted @ 2021-01-24 20:31 sxhyyq 阅读(36) 评论(0) 推荐(0) 编辑