python3+学习小知识整理,python where循环, python for循环,python 打印参数,python数组求和,python字符串替换等等,后续会持续更新。
#!/usr/bin/env python# -*- coding: utf-8 -*-#where循环count = 0while (count<10): print ('Th count is', count) count += 1 print ("down")pass#字符串转移print(arrayList[-1])print('\\\n\\')print(r'\\\r\\') #原样输出print('\n');print('---------------')print('\\\\')print(r'''hello,\nworld''')age = 1while (age<10): if (age>5): print("now nums=%s" % age) break pass else: print(r'---nums=%s' % age) age+=1test_array = ['kevin','ruby']print(len(test_array))print("len count array is =%s" % len(test_array))#数组末尾追加操作, append函数test_array.append('xxxxxxxxxxxxxx')print("python append array param=%s" % test_array)print(test_array)lists = ['name', 'quest', 'favorite color']print("array list is :%s" % lists)for i in range(len(lists)): print("key is =%s" % i , "value is =%s" % lists[i])print("---------------------")#循环判断,条件满足调出循环, range 函数 (开始值,结束之,+值/-值)for k in range(1,100,2): if k>20: print("now key is : %s" % k) break pass else: print("----k===%s" % k) print("---------------------")string_1 = "abcdefg"#统计字符串长度 len函数,可统计 array,string 等print("now string length is %s" % len(string_1), "nums")#字符串循环单个输出for k in string_1: print("_%s_" % k)print("字符串获取指定某一位的值===",string_1[5])#从指定位数后面开始替换,保留前面值print("字符替换函数:",string_1[:4]+'___testok!!!') #从指定位数+1开始替换后面,只保留当前位数+1的值print("字符替换函数:",string_1[4]+'___xxxxxxxxxxxx!!!') # 判断是否是整数print(isinstance(111, int))