小甲魚的Python
課程都是圍繞着一個個小遊戲,進行Python
的講解,由易入難。python
print('------------------我愛魚C工做室------------------')
temp = input("不妨猜一下小甲魚如今內心想的是哪一個數字:")
guess = int(temp)
if guess == 8:
print("我草,你是小甲魚內心的蛔蟲嗎?!")
print("哼,猜中了也沒有獎勵!")
else:
print("猜錯拉,小甲魚如今內心想的是8!")
print("遊戲結束,不玩啦^_^")
什麼是BIF
?程序員
BIF就是 Built-in functions,內置函數。爲了方便程序員快速編寫腳本程序,python提供了很是豐富的內置函數,咱們只須要直接調用便可,例如
print()
的功能就是打印到屏幕,input()
的做用就是接收用戶輸入web
Python3提供了多少個BIF
?編程
在IDLE中,輸入
dir(__builtins__)
,能夠看到Python提供的內置方法列表,其中小寫的就是BIF。若是想具體查看某個BIF功能,好比input()
,能夠在IDLE中輸入help(input)
編程語言>>> 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', 'WindowsError', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', '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(input) Help on built-in function input in module builtins: input(prompt=None, /) Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed to standard output without a trailing newline before reading input. If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError. On *nix systems, readline is used if available.
‘FishC’ 和 ‘fishc’ 同樣嗎?svg
不同。能夠在IDLE中輸入
'FishC' == 'fishc'
,進行測試函數>>> 'FishC' == 'fishc' False
Python中什麼是最重要的?你贊同嗎?測試
縮進!縮進是Python語言的靈魂,縮進使得python的代碼更加精簡,而且有層次。在python中對待縮進要十分當心的,由於若是沒有使用正確的使用縮進,代碼所作的事情就會和你所指望的相去甚遠ui
若是在正確的位置輸入
:
,IDLE會自動將下一行縮進!lua
上述例子中出現了=
和==
,都表示什麼含義?
==
:表示判斷是否相等
=
:表示賦值,把右邊的值給到左邊的變量裏面去
你據說過拼接
這個詞嗎?
在一些編程語言,咱們能夠將兩個字符串」相加」在一塊兒,如:
'I' +'Love' +'FishC'
會獲得'ILoveFishC'
,在python裏,這種作法叫作拼接字符串。
編寫程序:hello.py,要求用戶輸入姓名打印你好,xx!
name = input("請輸入您的姓名:")
print('你好,'+name+'!')
編寫程序:calc.py要求用戶輸入1到100之間的數字並判斷,輸入符合要求打印你妹好漂亮^_^
,不符合要求打印你大爺好醜T_T
temp = input("請輸入1到100之間的數字:")
num = int(temp)
if 1 <= num <= 100:
print('你妹好漂亮^_^')
else:
print('你大爺好醜T_T')