python3语法都相同吗_python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样...
python3.4學習筆記(一) 基本語法 python3不向下兼容,有些語法跟python2.x不一樣,IDLE shell編輯器,快捷鍵:ALT+p,上一個歷史輸入內容,ALT+n 下一個歷史輸入內容。#idle中按F5可以運行代碼
BIF --> built in functions 查詢python有多少BIF內置函數的方法: 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', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', '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(函數名)如: help(str)
helloworld.py
temp = input("input number:")
guess = int(temp)
if guess == 8:
print("is 8")
else:
print("is 8")
print("tab is useing")
print("out game")
frist = 3
second = 8
third = frist + second
print(third)
str1 = "string1"
str2 = " string2"
str3 = str1 + str2
print(str3)
------------------------------
input number:8
is 8
out game
11
string1 string2
結束語句不需要分號,:冒號后回車會自動縮進,tab鍵是有意義的,不僅僅是代碼縮進,縮進里面屬于同一個邏輯模塊。 在非邏輯層次結構的代碼前面不能使用空格,tab鍵。
變量不需要指定類型,會自動轉換。python沒有"變量",只有"名字"。變量就是可變的,變量使用之前需要先賦值。 數字相加,字符串拼接,字符串屬于文本。
#前后必須使用同樣的單引號或雙引號,必須是英文半角的字符。 print('5' + "8")
#反斜杠可以作為轉義字符串,原始字符串在字符串前面加上r即可,在結尾不能加反斜杠的
#跨越多行的字符串:三重引號字符串(可以是三個單引號或者三個雙引號),把內容放中間,可當成多行注釋使用
print('c:\\now I\'am')
print(''' line1
line3
''')
print("hello\n" * 3) #會打印3次
#注釋使用#號,如果是使說明性注釋,可以用__doc__ str.__doc__ #輸出str函數的文檔描述內容 python 的一個特點是不通過大括號 {} 來劃定代碼塊,而是通過...'__doc__', '__eq__', '__format__', '__ge__', '__getattribute...
============================================
#引入外部模塊 import random
#random模塊,randint(開始數,結束數) 產生整數隨機數
import random
secret = random.randint(1,10)
temp = input("請輸入一個數字\n")
guess = int(temp)
count = 0;
while guess != secret: #猜錯的時候才進入循環條件
if count == 0 and guess > secret:
print("猜大了")
if count == 0 and guess < secret:
print("猜小了")
temp = input("請重新輸入\n") #需要在判斷之前讓用戶輸入,否則猜對了就直接退出了
guess = int(temp)
count += 1 #不能使用count++這種方式
if count > 2:
print("猜錯4次自動退出了")
break #退出循環
if guess == secret:
print("恭喜,你猜對了")
print("猜對了也就那樣")
else:
if guess > secret:
print("猜大了")
else:
print("猜小了")
print("游戲結束")
總結
以上是生活随笔為你收集整理的python3语法都相同吗_python3.4学习笔记(一) 基本语法 python3不向下兼容,有些语法跟python2.x不一样...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle vitu,Supply C
- 下一篇: python运行外部程序_在Python