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))

结果

python基础【一】_开发语言

内建序列

pList = [(1, 2, 'asd'), (4, 5, 'fgh'), (7, 8, 'jkl')]
print(pList)
print(pList[0])
print(pList[0][1])

python基础【一】_开发语言_02

切片

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:])

python基础【一】_逆序_03

逆序

print(aList[::-1])

九九乘法表

for i in range(1, 10):
for j in range(1, i+1):
print("%d*%d=%-2d" % (j, i, i*j), end="\t")
print("")

python基础【一】_python_04

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)