Python 基础教程(变量类型和操作)

Python 变量类型和操作

由于最近一直在学英语,所有用英语给自己和其他同学写了一些python基础操作,方便随时查阅
里面有好多错误还请大佬见谅

1. Character string

The following code area is given operation:

# the definition  of variable
stringA = 'hello!World'
stringB = 'GoodBye!Wrold'
textFormat = '{}, {}'


# stringB will be append after stringA
stringA + stringB
# format function will added variable stringA and stringB into bracket of variable textFormat
textFormat.format(stringA, stringB)

2. List

# the definition of variable
list = {1, 2, 3}
listNew = {10, 11}

# quote = "this function will"
# the number of bracket of variable list equals the specific value in variable list
list[0]
list[1]
# the function of python
cmp(list, listNew) # this is a complicated function with complicated operation of comparison 
len(list) # #{quote} return the length of the variable list
max(list) # #{quote} return the minimum of the variable list
min(list) # #{quote} return the maximum of the variable list
list(seq) # #{quote} transform tuple into list
# the operation of add
list.append(4) # the number 4 will be appended after variable list
list.extend(listNew) # the variable listNew will be appended after variable list
# the operation of delete
list.remove(1) # it will remove the first elementary with value of 1
list.pop(1) # it will remove the second elementary
list.insert(3, 4) # it will insert number 4 as the fourth elementary

3. Tuple

# the difference between tuple and list is that the bracket of variable tuple if '()' and the bracket of variable list is []'
# and there is a function that is unique 
tuple(list) # this function will transform list into tuple

4. Dictionary

# quote = 'the method will'
# variable dictionary is identical with variable  json
# the python function of dictionary is identical with list
# and the following is the method of dictionary
dict.clear() # #{quote} clear all elemenrary of variable dict
dict.get(key, default=None) # #{quote} return the value of specific key that value is key, if there not exist a corresponding value that will return default value
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值