Python Legacy

#模块和函数导入和使用
import module_name
module_name.function_name()

import module_name as mn
mn.function_name()

from module_name import function_0, function_1, function_2
function_0()
function_1()
function_2()

from module_name import function_name as fn
fn()

from module_name import *
function_n()
#去空格,去掉空格后a和原来完全一样
>> a=" abc "
>>print(a.strip())
>>print(a.lstrip()) #左空格
>>print(a.rstrip()) #右空格
>> a
' abc '
#list中的数值的最大,最小,总和
>> digits = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
>> min(digits)
0
>> max(digits)
9
>> sum(digits)
45
#批量改变list的值
>>squares = [value**2 for value in range(1,11)]
>>print(squares)
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
#复制list
>>my_foods = ['pizza', 'falafel', 'carrot cake'] 
>>friend_foods = my_foods[:]
#关键字not in
>>banned_users = ['andrew', 'carolina', 'david']
>>user = 'marie'
>>if user not in banned_users:
...    print(user.title() + ", you can post a response if you wish.")
... 
Marie, you can post a response if you wish.

你可能感兴趣的:(Python Legacy)