1. 打印字符串 首先,我们需要使用print函数来打印字符串。在Python中,可以使用单引号或双引号来表示字符串。 # 打印字符串print('Hello, World!') 1. 2. 在上面的代码中,'Hello, World!'是一个字符串,在print函数中使用引号括起来,表示要打印这个字符串到控制台。 2. 打印数字 如果要在打印字符串的同时打...
1> str.count():计算字符串中包含多少个指定的子字符串 info = "abcdefa" print (info.count('a')) --- 2 2> str.startswith():检查字符串是否以指定的字符串开头 info = "this is tom" print (info.startswith("this")) --- True 3> str.endswith() :检查字符串是否以指定的字符串结尾 inf...
print (value,...,sep='',end='\n',file=sys.stdout,flush=False) 1. 从上面的语法格式可以看出,value 参数可以接受任意多个变量或值,因此 print() 函数完全可以输出多个值。例如如下代码: user_name = 'Charlie' user_age = 8 #同时输出多个变量和字符串 print("读者名:",user_name,"年龄:",user_a...