python3+学习小知识整理,python where循环, python for循环,python 打印参数,python数组求和,python字符串替换等等,后续会持续更新。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#where循环
count = 0
while (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,\n
world''')
age = 1
while (age<10):
if (age>5):
print("now nums=%s" % age)
break
pass
else:
print(r'---nums=%s' % age)
age+=1
test_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))