import mysql.connector mydb = mysql.connector.connect( host="localhost", # 数据库主机地址 user="yourusername", # 数据库用户名 passwd="yourpassword" # 数据库密码 ) print(mydb) import mysql.connector mydb = mysql.connector.connect( host="lo…
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…
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 ("已更新字…
#!/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 =",…
n = 100 sum = 0 counter = 1 while counter <= n: sum = sum + counter counter += 1 print("1 到 %d 之和为: %d" % (n,sum)) var = 1 while var == 1 : # 表达式永远为 true num = int(input("输入一个数字 :")) print ("你输入的数字是: ", num) print ("G…
if condition_1: statement_block_1 elif condition_2: statement_block_2 else: statement_block_3 var1 = 100 if var1: print ("1 - if 表达式条件为 true") print (var1) var2 = 0 if var2: print ("2 - if 表达式条件为 true") print (var2) print ("Good b…
import re print(re.match('www', 'www.runoob.com').span()) # 在起始位置匹配 print(re.match('com', 'www.runoob.com')) # 不在起始位置匹配 import re line = "Cats are smarter than dogs" # .* 表示任意匹配除换行符(\n.\r)之外的任何单个或多个字符 matchObj = re.match( r'(.*) are (.*?) .*', l…