python学习
努力准备秋招
这个作者很懒,什么都没留下…
展开
-
python 00-07 集合与布尔运算 s = {‘a‘, ‘b‘, ‘c‘}
1.集合(set)与字典相同均存储 key,但也只存储 key,因 key 不可重复,所以 set 的中的值不可重复,也是无序的。重复的元素在输出时,会自动过滤掉 2.创建一个集合 方法一(空集合法):my_set = set() my_set.add('python') 用了set()函数建立一个空集合,再往里面增加元素 方法二(定义直接创建):my_set={'python','love','me'} 直接用定义来进行创建 方法三:(使用set函数) # 使用 set 函数s = set([原创 2022-05-14 09:57:47 · 420 阅读 · 0 评论 -
python 00-06 元组 t=(1,2,3)
1.元组中元素不能被修改,我们要用重新赋值的方式操作 2.查找某个元素在列表中首次出现的位置(即索引),使用如下所示: # Use .index to enter a value and return the index t.index('one') # Use .count to count the number of times a value appears t.count('one') 上面两段语句,分别是对tuple里的‘one’索引它第一次出现的位置,第二句是数有多少‘one’这个i原创 2022-05-14 09:30:52 · 1000 阅读 · 0 评论 -
python 00-04 lists 列表
1.my_list= ['python', 12, 'AB'] python里面没有数组,但是引入了功能更为强大的list,list里面可以装不同类型的东西,比如字符串、字母、数字,除了数字,其他的都用单引号括起来 2.使用len()函数,能得知Listl里面有多少items len(my_list) 3. 4.使用append()函数 在list后面增加item # Append list1.append('append me!') 使用pop()函数把List索引位置为0的ite原创 2022-05-13 11:09:50 · 59 阅读 · 0 评论 -
python 00-03 string formatting字符串格式化
1.有三种string formatting的方式 2.第一种方法,使用formatting with placeholders 占位符格式化 %s print("I'm going to inject %s here." %'something') I'm going to inject something here. 也可以使用tuple来解决多个要插入的情况: print("I'm going to inject %s text here, and %s text here." %(原创 2022-05-13 08:59:18 · 590 阅读 · 0 评论 -
python学习 00-02 strings
1.creating a string (1)单引号双引号都可以,但要注意下面的这种情况。下面这个语句会报错,因为I am的缩写的单引号会和字符串开头的‘一起构成一对引号,让这个字符串提前结束 # Be careful with quotes! ' I'm using single quotes, but this will create an error' 这种情况改成双引号就好: "Now I'm ready to use the single quotes inside a string!原创 2022-05-11 16:16:55 · 240 阅读 · 0 评论 -
Python 01 variable assignment
1.classic division 和 floor divison 2.基本数据类型 整数 /integer 浮点型 Floating-point numbers 3.截断小数,不四舍五入,保留整数部分 结果为1 # Floor Division 7//4 4.取余运算 结果为3 # Modulo 7%4 5.求次方 结果为8 # Powers 2**3 6.开根号 结果为2.0 # Can also do roots this way 4**0.5 7.在命变量名(.原创 2022-05-11 14:45:58 · 240 阅读 · 0 评论