asky533 发表于 2022-8-18 23:42:11

零基础入门学习Python -- Day2 -- 学习笔记

下面是我的学习笔记,欢迎参考和学习{:5_109:}
这是第一个猜数字小游戏,笔记就以注释的形式表现出来:#p2_1.py
"""___第一个小游戏___"""
"""提示:注意缩进哟"""
# 这里利用input()函数取得用户输入的数字
temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")
# 这里吧temp转换一下数据类型,因为如果此时输入type(temp)(也就是显示temp的数据类型)时它会返回str,代表temp变量的数据类型是字符串,所以就要用int(x, base=10)函数来把temp变量转化为数字类型
guess = int(temp)
# 下面是一个条件语句,它的语法是这样的:
#if 条件:
#    执行结果
#elif 条件:
#    执行结果
#else:
#   执行结果
# 多说无益,钻进代码里就明白了。
# 这里是判断如果用户输入的数字是8,那么就胜利了。注意:这里是两个等号,因为一个等号代表的意思是给一个变量赋值,而两个等号才表示等于
if guess == 8:
    print("你是小甲鱼心里的蛔虫吗?")
    print("哼,猜中了也没有奖励!")
else:
    print("猜错啦,小甲鱼心里想的是8!")
# 跳出循环时执行,也就是执行完上面的条件语句时才执行下面的语句
print("游戏结束,不玩啦^_^")
这是Python中的全部BIF:
>>># 首先我们调用Python中的dir()函数,让它把所有Python中的BIF打印出来
>>>dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EncodingWarning', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'aiter', 'all', 'anext', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']
>>>
注:BIF就是Built-in Functions,就是指的Python的内置函数,内置函数存在的意义就是为了方便快捷。Python里边就有许多现成的内置函数,什么print()呀input()呀全都是BIF。
那么要是不知道某个BIF该怎么用怎么办呢?请参考下面的代码:
>>># 先举个例子吧:如果我们要获取print()函数的用法,就可以调用help()这个内置函数。举个例子:
>>>help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
   
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.

>>>#以上的一大堆东西就是print()函数的用法,大家感兴趣的话可以用google翻译一下。
让我们一起加油吧!{:5_91:}

螃谢本谢 发表于 2022-8-19 20:43:59

{:10_256:}{:10_256:}{:10_256:}{:10_256:}

惊晓欲仙 发表于 2022-8-20 11:56:36

{:10_279:}

hornwong 发表于 2022-8-21 20:01:18

{:5_108:}

kongminghui 发表于 2022-8-22 10:38:55

{:5_109:}

1885102 发表于 2022-8-22 14:38:04

买两本小甲鱼老师的书,一本看,一本收藏

yhj122 发表于 2022-8-22 20:16:00

谢谢

张w 发表于 2022-10-5 17:44:48

{:5_102:}

康涵阳 发表于 2022-10-7 13:35:13

厉害啦
页: [1]
查看完整版本: 零基础入门学习Python -- Day2 -- 学习笔记