<jupyter_start><jupyter_text>lamda<jupyter_code>def test(f, a, b): 
    print(f(a, b))
fun = lambda x,y:x**2+y
test(fun,2,3)<jupyter_output><empty_output><jupyter_text>程序作用域<jupyter_code>def f(x):
     a = 7
     print(a + x)
a = 5
f(3)
print(a)
# Error
a=3
print(a ** b)#print NameError<jupyter_output><empty_output><jupyter_text>布尔表达式<jupyter_code>x = None
if x:
    print("x is true")
else:
    print("x is false")

x = 0
if x:
    print("x is true")
else:
    print("x is false")
    
x = []
if x:
    print("x is true")
else:
    print("x is false")    
x = {}
if x:
    print("x is true")
else:
    print("x is false")    

x = {1}
if x:
    print("x is true")
else:
    print("x is false")<jupyter_output><empty_output><jupyter_text>String<jupyter_code># 使用dir 列出所有str的内建函数 并查找up开头的函数
[nameWithUp for nameWithUp in  dir(str) if nameWithUp.startswith('up') ]
SingASong = "The sun is rising. The sunlight is shinning on the wind"
SingASong.upper()<jupyter_output><empty_output><jupyter_text>upper split join find encode decode<jupyter_code>SingASong.split(' ')
'[]'.join(SingASong.split(' '))
SingASong.find("The")
# encode
type("你好".encode('utf-8'))
"你好".encode('utf-8')
# encode list of python  ,can refer to https://docs.python.org/2.4/lib/standard-encodings.html
("你好".encode('utf-8')).decode('utf_8') # utf-8 , utf_8 are both work here
# help(bytes.decode)<jupyter_output><empty_output><jupyter_text>转义字符![QQ%E5%9B%BE%E7%89%8720200107202821.png](attachment:QQ%E5%9B%BE%E7%89%8720200107202821.png)<jupyter_code># \ooo表示8进制, \xxx表示16进制
print('\101\t\x41');print('\141\t\x61')
print('\102\n\x41');print('\142\n\x62')
help(bytes.decode)<jupyter_output><empty_output><jupyter_text>列表  列表解析<jupyter_code># [expression for expr1 in sequence1
#             for expr2 in sequence2
#              ...
#             for exprn in sequencen
#                 if condition]
[x**2 for x in range(10) for y in range(10)  if x**2<50]
[(x+1,y+1) for x in range(2) for y in range(2)]<jupyter_output><empty_output><jupyter_text>列表的浅拷贝<jupyter_code>#浅拷贝只完成列表x的第一层元素的拷贝，第二层元素（这里是[3,4])没有拷贝，拷贝的操作会产生新的对象
x = [1,2,[3,4]]
y = x.copy()
y[0],y[2][0]=9,9
x,y #x[2][0]也发生了改变
x = [1,2,[3,4]]
y = x.copy()
y[0],y[2]=9,[9,4]#此处是重新指向新的对象
x,y<jupyter_output><empty_output><jupyter_text>列表深拷贝<jupyter_code>import copy
# help(copy)
# help(copy.deepcopy)
y=copy.deepcopy(x)
y[0],y[2][0]=8,8
x,y<jupyter_output><empty_output><jupyter_text>输入输出<jupyter_code>#如何输入得到一个均为数值型的列表
# lst = eval(input('enter a list'))
lst = list(input('enter numbers'))
lst = list(eval(input('enter numbers')))
# help(list)
lst
#eval 会只能分析输入的数值类型， 'abc',33 分别会转成 字符串和数值
x,y = eval(input('enter two params'))
x,y
# print(eval('',22,['p','y','thon']))
# print(eval('124857'))
print(eval('ab'))



#如何将循环输出的数据放在同一行
for i in range(4):
    print(i,i+1,i+2,sep=',',end=' ')<jupyter_output><empty_output><jupyter_text>函数式编程  map 函数<jupyter_code>#map 函数使用
lst=[11,22,33]
list(map(str,lst))#map 将lst每个元素作为参数传入str函数得到的返回值作为新的元素
#map 函数 对列表元素转化大写
lst = ['fade','away','show']
list(map(upper,lst))
list(map(lambda x:x.upper(),lst))<jupyter_output><empty_output><jupyter_text>函数式编程应用2000个5（55555...55555）除以84的余数<jupyter_code>from functools import reduce;reduce(lambda x,y:(x*10+y)%84 ,([5])*2000 )
dir(__builtins__)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1871951219512195, 'fraction_numerical': 0.051829268292682924, 'mean_word_length': 5.995735607675906, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 49, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '495196', 'license': 'MIT', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1632, 'n_words': 237, 'path': 'basic/ch01.ipynb', 'repo_name': 'creasy-pita/pythondata-book-note', 'size': '3280'}