zoukankan      html  css  js  c++  java
  • 0基础入门学习Python(第1-2章)

    第一章:就这么愉快的开始吧

    1.1获取Python

    Python3.7

    1.2从idle启动

    Python 3.7.3 (default, Mar 27 2019, 09:23:39)
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print("I Love China")
    I Love China
    >>>

    1.3失败的尝试

    Python2

    Python 2.7.16 (default, Mar 4 2019, 09:02:22)
    [GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print "I Love China"
    I Love China
    >>>

    Python 3.7.3 (default, Mar 27 2019, 09:23:39)
    [Clang 10.0.0 (clang-1000.11.45.5)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print("I Love China")
    I Love China
    >>> print "I Love China"
    File "<stdin>", line 1
    print "I Love China"
    ^
    SyntaxError: Missing parentheses in call to 'print'. Did you mean print("I Love China")?
    >>>

    1.4尝试点新的东西

    >>> print(5+3)
    8
    >>> 5+3
    8
    >>> 1234567890987654321 * 9876543210123456789
    12193263121170553265523548251112635269
    >>> print("Well water " + "River")
    Well water River
    >>>

    1.5  为什么会这样

    >>> print("I Love China " * 3)
    I Love China
    I Love China
    I Love China

    >>> print("I Love China " + 3)
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: can only concatenate str (not "int") to str
    >>>

    第二章:用Python设计第一个游戏

    猜数字游戏

    # date: 2019/8/13
    '''----第一个小游戏---'''
    
    temp = input("不妨猜一下小甲鱼现在心里想的是哪个数字:")
    guess = int(temp)
    
    if guess == 8:
        print("你是小甲鱼心里的蛔虫吗?")
        print("哼,猜中了也没有奖!")
    else:
        print("猜错了,小甲鱼现在心里想的是8!")
    print("游戏结束,不玩啦!^_^")

    游戏运行下:

    BIF 概念

    BIF 就是built-in function 内置函数的意思。为了方便程序员快速的编写脚本,Python提供了非常丰富的内置函数,只需要直接引用即可。

    print() 就是一个内置函数,他的功能就是,打印到屏幕。

    查看Python内置的函数。

    >>> dir(__builtins__)
    ['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', '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', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', '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']
    >>>

    help() 用于显示BIF的功能描述

    >>> help(print)

    Help on built-in function print in module builtins:

    print(...)
    print(value, ..., sep=' ', end=' ', 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.

    完!

  • 相关阅读:
    openldap
    Java实现 洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…
    Java实现 洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…
    Java实现 洛谷 P2141 珠心算测验
    Java实现 洛谷 P2141 珠心算测验
    Java实现 洛谷 P2141 珠心算测验
    Java实现 洛谷 P2141 珠心算测验
    Java实现 洛谷 P2141 珠心算测验
    Java实现 洛谷 P1567 统计天数
    Java实现 洛谷 P1567 统计天数
  • 原文地址:https://www.cnblogs.com/hack404/p/11349033.html
Copyright © 2011-2022 走看看