Python3教學
Python3引入什麼新的東西?
Python3環境安裝設置
Python3基礎語法
Python3變量類型
Python算術運算符實例
Python3比較運算符實例
Python3賦值運算符實例
Python3位運算符實例
Python3邏輯運算符實例
Python3成員運算符實例
Python3標識運算符實例
Python3運算符優先級示例
Python3基本運算符
Python3 if語句
Python3 if...elseif...else語句
Python3嵌套if語句
Python3決策
Python3 while循環語句
Python3 for循環語句
Python3嵌套循環
Python3 break語句
Python3 continue語句
Python3 pass語句
Python3循環
Python3 abs()函數
Python3 ceil()函數
Python3 exp()函數
Python3 fabs()函數
Python3 floor()函數
Python3 log()函數
Python3 log10()函數
Python3 max()函數
Python3 min()函數
Python3 modf()函數
Python3 pow()函數
Python3 round()函數
Python3 sqrt()函數
Python3 choice()函數
Python3 randrange()函數
Python3 random()函數
Python3 seed()函數
Python3 shuffle()函數
Python3 uniform()函數
Python3 acos()函數
Python3 asin()函數
Python3 atan()函數
Python3 atan2()函數
Python3 cos()函數
Python3 hypot()函數
Python3 sin()函數
Python3 tan()函數
Python3 degrees()函數
Python3 radians()函數
Python3數字
Python3 string.capitalize()方法
Python3 string.center()方法
Python3 string.count()方法
Python3 string.decode()方法
Python3 string.endswith()方法
Python3 string.expandtabs()方法
Python3 string.encode()方法
Python3 string.find()方法
Python3 string.index()方法
Python3 string.isalnum()方法
Python3 string.isalpha()方法
Python3 string.isdigit()方法
Python3 string.tolower()方法
Python3 string.isnumeric()方法
Python3 string.isspace()方法
Python3 string.istitle()方法
Python3 string.isupper()方法
Python3 string.join()方法
Python3 string.len()方法
Python3 string.ljust()方法
Python3 string.lower()方法
Python3 string.lstrip()方法
Python3 string.maketrans()方法
Python3 string.max()方法
Python3 string.min()方法
Python3 string.replace()方法
Python3 string.rfind()方法
Python3 string.rindex()方法
Python3 string.rjust()方法
Python3 string.rstrip()方法
Python3 string.split()方法
Python3 string.splitlines()方法
Python3 string.startswith()方法
Python3 string.strip()方法
Python3 string.swapcase()方法
Python3 string.title()方法
Python3 string.translate()方法
Python3 string.upper()方法
Python3 string.zfill()方法
Python3 string.isdecimal()方法
Python3字符串
Python3 list.cmp()方法
Python3 list.len()方法
Python3 list.max()方法
Python3 list.min()方法
Python3 list.list()方法
Python3 list.append()方法
Python3 list.count()方法
Python3 list.extend()方法
Python3 list.index()方法
Python3 list.insert()方法
Python3 list.pop()方法
Python3 list.remove()方法
Python3 list.reverse()方法
Python3 list.sort()方法
Python3列表
Python3 tuple.cmp()方法
Python3 tuple.len()方法
Python3 tuple.max()方法
Python3 tuple.min()方法
Python3 tuple.tuple()方法
Python3元組
Python3 dictionary.cmp()方法
Python3 dictionary.len()方法
Python3 dictionary.str()方法
Python3 dictionary.type()方法
Python3 dictionary.clear()方法
Python3 dictionary.copy()方法
Python3 dictionary.fromkeys()方法
Python3 dictionary.get()方法
Python3 dictionary.has_key()方法
Python3 dictionary.items()方法
Python3 dictionary.keys()方法
Python3 dictionary.setdefault()方法
Python3 dictionary.update()方法
Python3 dictionary.values()方法
Python3字典
Python3 time.altzone()方法
Python3 time.asctime()方法
Python3 time.clock()方法
Python3 time.ctime()方法
Python3 time.gmtime()方法
Python3 time.localtime()方法
Python3 time.mktime()方法
Python3 time.sleep()方法
Python3 time.strftime()方法
Python3 time.time()方法
Python3 time.tzset()方法
Python3日期和時間
Python3函數
Python3模塊
Python3 file.close()方法
Python3 file.tell()方法
Python3 file.truncate()方法
Python3 file.write()方法
Python3 file.writelines()方法
Python3 file.flush()方法
Python3 file.fileno()方法
Python3 file.isatty()方法
Python3 file.next()方法
Python3 file.read()方法
Python3 file.readline()方法
Python3 file.readlines()方法
Python3 file.seek()方法
Python3文件方法
Python3 os.access()方法
Python3 os.chdir()方法
Python3 os.chflags()方法
Python3 os.chmod()方法
Python3 os.chown()方法
Python3 os.chroot()方法
Python3 os.close()方法
Python3 os.closerange()方法
Python3 os.dup()方法
Python3 os.dup2()方法
Python3 os.fchdir()方法
Python3 os.fchmod()方法
Python3 os.fchown()方法
Python3 os.fdatasync()方法
Python3 os.fopen()方法
Python3 os.fpathconf()方法
Python3 os.fstat()方法
Python3 os.fstatvfs()方法
Python3 os.fsync()方法
Python3 os.ftruncate()方法
Python3 os.getcwd()方法
Python3 os.getcwdu()方法
Python3 os.isatty()方法
Python3 os.lchflags()方法
Python3 os.lchmod()方法
Python3 os.lchown()方法
Python3 os.link()方法
Python3 os.listdir()方法
Python3 os.lseek()方法
Python3 os.lstat()方法
Python3 os.major()方法
Python3 os.makedev()方法
Python3 os.makedirs()方法
Python3 os.minor()方法
Python3 os.mkdir()方法
Python3 os.mkfifo()方法
Python3 os.mknod()方法
Python3 os.open()方法
Python3 os.openpty()方法
Python3 os.pathconf()方法
Python3 os.pipe()方法
Python3 os.popen()方法
Python3 os.read()方法
Python3 os.readlink()方法
Python3 os.remove()方法
Python3 os.removedirs()方法
Python3 os.rename()方法
Python3 os.renames()方法
Python3 os.rmdir()方法
Python3 os.stat()方法
Python3 os.stat_float_times()方法
Python3 os.statvfs()方法
Python3 os.symlink()方法
Python3 os.tcgetpgrp()方法
Python3 os.tcsetpgrp()方法
Python3 os.tempnam()方法
Python3 os.tmpfile()方法
Python3 os.tmpnam()方法
Python3 os.ttyname()方法
Python3 os.unlink()方法
Python3 os.utime()方法
Python3 os.walk()方法
Python3 os.write()方法
Python3 os文件目錄的方法
Python3文件操作
Python3標準異常
Python3斷言
Python3異常處理

Python算術運算符實例

假設變量 a=10 和 變量b=20,然後:

操作符

描述

示例

將操作符的兩側數值增加(加法運算)

a + b = 30

左操作數減去右操作數

a – b = -10

操作符兩側數據相乘(乘法運算)

a * b = 200

操作符左側操作數除以右操作數

b / a = 2

左操作數除以右側操作數的餘數

b % a = 0

** 

執行指數(冪)計算

a**b 就是10 的20 次冪

//

地板除 - 除法不管操作數爲何種數值類型,總是會捨去小數部分,返回數字序列中比真正的商小的最接近的數字

9//2 = 4 以及 9.0//2.0 = 4.0

示例

假設變量 a = 10和變量 b = 20,那麼 -

#!/usr/bin/python3

a = 21
b = 10
c = 0

c = a + b
print ("Line 1 - Value of c is ", c)

c = a - b
print ("Line 2 - Value of c is ", c )

c = a * b
print ("Line 3 - Value of c is ", c)

c = a / b
print ("Line 4 - Value of c is ", c )

c = a % b
print ("Line 5 - Value of c is ", c)

a = 2
b = 3
c = a**b
print ("Line 6 - Value of c is ", c)

a = 10
b = 5
c = a//b
print ("Line 7 - Value of c is ", c)

當你執行上面的程序,它會產生以下結果 -

Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2.1
Line 5 - Value of c is 1
Line 6 - Value of c is 8
Line 7 - Value of c is 2