摘要: print("%s is %s years old" % ('bob', 23)) # 常用 print("%s is %d years old" % ('bob', 23)) # 常用 print("%s is %d years old" % ('bob', 23.5)) # %d是整数 常用 print("%s is %f years old" % ('bob', 23.5)) pri... 阅读全文
posted @ 2019-05-17 17:28 hejp 阅读(202) 评论(0) 推荐(0) 编辑
摘要: py_str = 'hello world!' print(py_str.capitalize()) # 第一个字母大写 print(py_str.title()) # 首字母大写 print(py_str.center(50)) # 字符串放50空格中间 print(py_str.center(50, '#')) # 字符串放50个*的中间 print(py_str.ljust(50, ... 阅读全文
posted @ 2019-05-17 17:16 hejp 阅读(280) 评论(0) 推荐(0) 编辑
摘要: alist = [10,'john'] for ind in range(len(alist)): print('%s: %s' %(ind, alist[ind])) for item in enumerate(alist): print('%s: %s' % (item[0], item[1])) for ind, val in enumerate(alist): ... 阅读全文
posted @ 2019-05-17 17:06 hejp 阅读(132) 评论(0) 推荐(0) 编辑
摘要: from random import randint # randint用于生成一个指定范围内的整数 alist = list() print(list('hello')) print(list((10,20,30))) astr = str() print(str(10)) print(str(['h','e','l','l','o'])) atuple = tuple() print(... 阅读全文
posted @ 2019-05-17 15:01 hejp 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 思路:1、设置一个用于随机取出字符的基础字符串,本例使用大小写字母加数字。2、循环n次,每次随机取出一个字符。3、将各个字符拼接起来,保存到变量result中。 阅读全文
posted @ 2019-05-17 14:50 hejp 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 每一个以py作为扩展名的文件都是一个模块。 结果输出: 阅读全文
posted @ 2019-05-17 14:41 hejp 阅读(165) 评论(0) 推荐(0) 编辑