入门学习python

入门学习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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值