跳至主要內容
11 Python for loop

1. for循环

lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for number in lst:
    print (f"{number}: {number*'*'}")

Cindy原创...大约 1 分钟python notebooknotespython
11 Python while

1. while 循环

当满足条件是一直执行里面的代码块

user_answer_correct = False
while not user_answer_correct:
    user_gender = input("Please input your gender(F/M): ")
    if user_gender == 'F':
        print("Your are a girl")
        user_answer_correct = True
    elif user_gender == 'M':
        print("Your are a boy")
        user_answer_correct = True
    else:
        print("Wrong inout, please input F or M")

 










Cindy原创...大约 5 分钟python notebooknotespython
10 Python if

python代码缩进问题

用四个空格或者一个tab表示缩进都可以,但不要混用。

相同位置表示他们是同一个代码块

while True:
 if True:
        print('hhhh')
 print('bo')

Cindy原创...大约 3 分钟python notebooknotespython
09 Python boolean value

1.布尔值的意义

用于表示判断中的是与否。一般用于条件测试当中

In [1]: a = True

In [2]: print(a)
True

In [3]: 10<5
Out[3]: False


Cindy原创...大约 1 分钟python notebooknotespython
08 Python set

1. 创建集合

  1. 直接用花括号创建集合
set1 = {1, 2, 3, 4, 5, 6, 7, 8}

Cindy原创...大约 1 分钟python notebooknotespython
07 Python dictionary

1. 如何创建一个电话薄

我们现在有下面的联系人:

姓名 手机号
李雷 123456
韩梅梅 132456
大卫 154389
Mr.Liu 131452
Bornforthis 180595
Alexa 131559

Cindy原创...大约 6 分钟python notebooknotespython
06 Python tuple

1.创建元组

  • 使用小括号创建
  • 里面的元素用英文逗号隔开
tup = ('毒药', '解药', '感冒药')
print(tup, type(tup))
#output
('毒药', '解药', '感冒药') <class 'tuple'>

Cindy原创...大约 3 分钟python notebooknotespython
05 Python list__Exercise
image-20231230164639809
numbers = list('132569874')
numbers_even_position = numbers[::2]
numbers_even_position.sort(reverse=True)
numbers[::2] = numbers_even_position
print(numbers)

#output
['8', '3', '6', '5', '4', '9', '2', '7', '1']

Cindy原创...小于 1 分钟python notebooknotespython
05 Python list

1. 列表结构

  • 利用中括号表示列表
  • 列表内元素用逗号隔开
  • 注意是英文输入法下的逗号
student1 = ['lilei', 18, 'class01', 201901]
student2 = ['hanmeimei', 19, 'class02', 201902]

Cindy原创...大约 10 分钟python notebooknotespython
04 Python string

1.字符串的定义

字符串是由字母,数字和特殊字符组成的特殊序列

image-20231214083505664

2.创建字符串

如何创建字符串?

——使用单引号,双引号或者三引号

name = ‘Cindy’
number =31”
paragraph = '''Hello everyone!
hello Cindy!'''

Cindy原创...大约 19 分钟python notebooknotespython