• 2024-08-05CS50P: 9. Et Cetera
    setpython’sdocumentationofset类型数学上的集合,没有重复元素Q:统计有多少个不同名houseway1--liststudents=[{"name":"Hermione","house":"Gryffindor"},{"name":"Harry","house":"
  • 2024-07-21CS50P: 7. Regular Expressions
    RegularExpressions/Regexes判断用户是否输入邮箱地址
  • 2024-07-18CS50P: 6. File I/O
    FileI/Olist相关函数python:listappend()向列表末尾添加元素list.append(element)sorted(*,key=None,reverse=False)Python:sortedsortsthelistinplace,usingonly<comparisonsbetweenitemskey:eg.key=str.lower()说明用小写来排序,但是列表还是
  • 2024-07-16CS50P: 5. Unit Tests
    assertPython:assert.calculator.py:defmain():x=int(input("What'sx?"))print("xsquaredis",square(x))defsquare(n):returnn+n #刻意为之if__name__=="__main__":main()test_calculator.py:f
  • 2024-07-15CS50P: 4. Libraries
    libraries,moduleslibrariesarebitsofcodewrittenbyyouorotherswecanuseinourprogramPythonallowsustosharefunctionsorfeatureswithothersas"modules"randompython:randomrandomisalibrarythatcomeswithPythonthatweco
  • 2024-07-11CS50P: 2. Loops
    control+C终止循环while循环#meow3timesi=0whilei<3:print("meow")i+=1 #python中没有i++for循环foriin[0,1,2]:print("meow")i初始为1,依次取2、3in可以让i按序取遍list中的元素,其中元素可以是int,dict,str,etc.for_in
  • 2024-07-10CS50P: 1. Conditionals
    运算符python中有>=和<=,其余和C一样python支持90<=score<=100CPython||or&and布尔运算TrueorFalse选择语句ififx<y:print("xislessthany")ifx>y:print("xisgreaterthany")ifx==y: