入门学习python第一天
主要看了一下list、tuple、if、for、dict、set的用法
def string() :
num = 10
# print('Hello World')
print('你今年{0}岁'.format(num))
print('这是%d%%' % (num))
def listLearn() :
classmates = ['Michael', 'Bob', 'Tracy']
print(len(classmates))
print(classmates[-1]) # the back one
classmates.append('ygl')
print(classmates)
# can choice index to pop, also default value is back value
# classmates.pop(index)
# print(classmates)
# tuple is not can change, not append(), pop() ans so on function
def tupleLearn() :
# note the (), not []
# if only one value, must define as (1,), append ','
tul = (1, 2, 3)
print(tul)
tup = ('a', ['A', 'B'])
print(tup)
tup[1][0] = 'B'
print(tup)
# io and if
def ioAndIf() :
age = int(input('age is :'))
if(age >= 18) : print('adult')
else : print('kid')
def forTest() :
# range(n) can produce 0 ` (n - 1) numbers
# such calculate 1 - 100 sum
sum = 0
for x in range(101) :
sum += x
print(sum)
# set up the step length
for x in range(0, 11, 2) :
print(x, end= ' ')
def dictTest() :
map = {'ysl' : 98, 'ygl' : 100}
print(map['ysl'])
if('ysl' in map) : print(map['ysl'])
# can use pop function delete the key
# set like C++STL set, set not Repeated elements
s = set([1, 2, 2])
# will print 1 2, wiped out the repeated elements
s.add(3)
s.remove(1)
print(s)
def someFunction():
# such as max, abs, int(), str(), hex()
pass
if __name__ == '__main__':
# string()
# listLearn()
# tupleLearn()
# ioAndIf()
# forTest()
# dictTest()