python基础【一】
原创
©著作权归作者所有:来自51CTO博客作者wx633288bd5c53e的原创作品,请联系作者获取转载授权,否则将追究法律责任
python基础
字符串
aStr = "hello world"
print(aStr, end='\n')
列表
aList = [1, 2, 3, 'asd', 'a']
print(aList, end='\n')
print(aList[3], end='\n')
元组
aTuple = (1, 2, "abc", 4)
print(aTuple)
range生成递增不可变列表
print(type(range(10)))
x = range(10)
print(x)
print(list(x))
结果
内建序列
pList = [(1, 2, 'asd'), (4, 5, 'fgh'), (7, 8, 'jkl')]
print(pList)
print(pList[0])
print(pList[0][1])
切片
aStr = "hello world"
print(aStr, end='\n')
print(aStr[0:6])
aList = [1, 2, 3, 'asd', 'a']
索引
print(aList[0])
print(aList[-5])
列表
aList = [1, 2, 3, 'asd', 'a']
print(aList, end='\n')
print(aList[3], end='\n')
print(aList[:-1])
print(aList[-5:])
逆序
九九乘法表
for i in range(1, 10):
for j in range(1, i+1):
print("%d*%d=%-2d" % (j, i, i*j), end="\t")
print("")
1-100的和
sum = 0
for i in range(1,101):
sum += i
print(sum)
1-10偶数的和
sum = 0
i = 0
while i<=10 :
if i % 2 == 0:
sum += i
print(i)
i += 1
print(sum)