跳至主要內容
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
Python exercise

Chapter1 after class test

  1. 以下哪个变量可以做 Python 的变量: C

    A. 01a B. class C. a_int D. b-int

  2. 以下哪个选项不是 Python 的基本数据类型关键字 C

    A. int B.bool C. string D. dict

  3. 此题无需在线作答,请在纸上作答后查看答案解析

    语句 x, y, z = 1, 2, 3 执行后,变量 y 的值为. 2

  4. 查看变量类型的 Python 内置函数是. type()

  5. 此题无需在线作答,请在纸上作答后查看答案解析

    请写出该代码的输出结果. XYZ

    a = 'ABC'
    b = a
    a = 'XYZ'
    print(b)
    

Cindy原创...大约 5 分钟python notebookpracticepython
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