import os, sys # 假定 /tmp/foo.txt 文件存在,并有读写权限 ret = os.access("/tmp/foo.txt", os.F_OK) print ("F_OK - 返回值 %s"% ret) ret = os.access("/tmp/foo.txt", os.R_OK) print ("R_OK - 返回值 %s"% ret) ret = os.access("/tmp/foo…
import mysql.connector mydb = mysql.connector.connect( host="localhost", # 数据库主机地址 user="yourusername", # 数据库用户名 passwd="yourpassword" # 数据库密码 ) print(mydb) import mysql.connector mydb = mysql.connector.connect( host="lo…
var1 = 'Hello World!' var2 = "Runoob" #!/usr/bin/python3 var1 = 'Hello World!' var2 = "Runoob" print ("var1[0]: ", var1[0]) print ("var2[1:5]: ", var2[1:5]) #!/usr/bin/python3 var1 = 'Hello World!' print ("已更新字…
print ("abs(-40) : ", abs(-40)) print ("abs(100.10) : ", abs(100.10)) #!/usr/bin/python3 import math # 导入 math 模块 print ("math.ceil(-45.17) : ", math.ceil(-45.17)) print ("math.ceil(100.12) : ", math.ceil(100.12)) p…
#!/usr/bin/python3 a = 21 b = 10 c = 0 c = a + b print ("1 - c 的值为:", c) c = a - b print ("2 - c 的值为:", c) c = a * b print ("3 - c 的值为:", c) c = a / b print ("4 - c 的值为:", c) c = a % b print ("5 - c 的值为:",…
#!/usr/bin/python3 counter = 100 # 整型变量 miles = 1000.0 # 浮点型变量 name = "runoob" # 字符串 print (counter) print (miles) print (name) #!/usr/bin/python3 str = 'Runoob' print (str) # 输出字符串 print (str[0:-1]) # 输出第一个到倒数第二个的所有字符 print (str[0]) # 输出字符串第一个字…
#!/usr/bin/python3 # 第一个注释 print ("Hello, Python!") # 第二个注释 #!/usr/bin/python3 # 第一个注释 # 第二个注释 ''' 第三注释 第四注释 ''' """ 第五注释 第六注释 """ print ("Hello, Python!") if True: print ("True") else: print (&q…
def 函数名(参数列表): 函数体 # 计算面积函数 def area(width, height): return width * height def print_welcome(name): print("Welcome", name) print_welcome("Runoob") w = 4 h = 5 print("width =", w, " height =", h, " area =",…
<Directory "/var/www/cgi-bin"> AllowOverride None Options +ExecCGI Order allow,deny Allow from all </Directory> print ("Content-type:text/html") print () # 空行,告诉服务器结束头部 print ('<html>') print ('<head>') print ('…
tup1 = ('Google', 'Runoob', 1997, 2000) tup2 = (1, 2, 3, 4, 5, 6, 7 ) print ("tup1[0]: ", tup1[0]) print ("tup2[1:5]: ", tup2[1:5]) tup1 = (12, 34.56); tup2 = ('abc', 'xyz') # 以下修改元组元素操作是非法的. # tup1[0] = 100 # 创建一个新的元组 tup3 = tup1 + tu…