李珞寧python內建built-in函數function迴圈loop範圍range
程式碼
print("練習函數bin, hex, integer")
print("4轉二進位",bin(4))
print("7轉二進位",bin(7))
print(4+2+1)
print("20轉成16進位",hex(20))
print("FF轉成10進位",int("FF",16))
print("練習函數abs, all, any, ascii")
for i in range(-2,3):
x = abs(i)
print(abs(x))
print("all邏輯,是否全部是真?")
x, y, z = 1==1, 2>1, 3>2 #=給值,==判斷
print(all([x,y,z]))
print("2>1,-1==1,-2>3有正確的嗎",any([2>1, -1==1, -2>3]))
print("2>1,-1==1,-2>3全正確嗎",all([2>1, -1==1, -2>3]))
#pthon註解range(開始,結束)
print("列印,迴圈for, range範圍")
for i in range(33301, 33344):
print("字碼character", i,"是",chr(i))
for i in range(65, 70):
print(chr(i))
w3schools內建函數列表
href="https://www.w3schools.com/python/python_ref_functions.asp"Python has a set of built-in functions.
| Function | Description |
|---|---|
| abs() | Returns the absolute value of a number |
| all() | Returns True if all items in an iterable object are true |
| any() | Returns True if any item in an iterable object is true |
| ascii() | Returns a readable version of an object. Replaces none-ascii characters with escape character |
| bin() | Returns the binary version of a number |
| bool() | Returns the boolean value of the specified object |
| bytearray() | Returns an array of bytes |
| bytes() | Returns a bytes object |
| callable() | Returns True if the specified object is callable, otherwise False |
| chr() | Returns a character from the specified Unicode code. |
| classmethod() | Converts a method into a class method |
| compile() | Returns the specified source as an object, ready to be executed |
| complex() | Returns a complex number |
| delattr() | Deletes the specified attribute (property or method) from the specified object |
| dict() | Returns a dictionary (Array) |
| dir() | Returns a list of the specified object's properties and methods |