当前位置:网站首页>[learning progress on June 3]
[learning progress on June 3]
2022-07-16 07:15:00 【Struggling youth, come on】
1.Git command
2. Python- Refactoring functions
# 10.4.3 restructure Divide the code into a series of functions that do specific work , This process is called refactoring .
# Refactoring makes the code clearer 、 Easier to understand 、 It's easier to expand .
# Most of the logic can be put into one or more functions .
def greet_user():
""" Greeting users , And point out the name """
filename2 = 'username.json'
try:
with open(filename2) as file_obj:
username = json.load(file_obj)
except FileNotFoundError:
username = input(' What is your name? ?')
with open(filename2, 'w') as file_obj:
json.dump(username, file_obj)
print(' We will remember you when you come back ,' + username + '.')
else:
print(' welcome back ,' + username + '.')
greet_user()
# Let's reconstruct the function greet_user()
def get_stored_username(): # New function
""" If the user name is stored , Just get it """
filename2 = 'username.json'
try:
with open(filename2) as file_obj:
username = json.load(file_obj)
except FileNotFoundError:
return None
else:
return username
def get_new_username():
""" Prompt the user to enter a user name """
username = input(' What is your name? ?')
filename2 = 'username.json'
with open(filename2, 'w') as file_obj:
json.dump(username, file_obj)
return username
def greet_user():
""" Greeting users , And point out the name """
username = get_stored_username()
if username:
print(' welcome back ,' + username + '.')
else:
username = get_new_username()
print(' We will remember you when you come back ,' + username + '.')
greet_user()# notes : Each function performs a single and clear task , We call greet_user(), Print a message , Or welcome old users back , Or greet new users . # First call get_stored_username(), Calling get_new_username()
3. mysql
such as :“ . ”, '[ ]', ' | ', ' - ', Wait, there are other characters , How can I match these characters ?
Example :select vend_name from django_apps_vendor where vend_name regexp "." order by
| vend_name |
+----------------+
| ACME |
| Anvils R Us |
| Furball Inc. |
| Jet Set |
| Jouets Et Ours |
| LT Supplies |
+----------------+
Such output is not the output we want , So we also need to use before matching special characters \\.
\\-: On behalf of the match -, \\.: On behalf of the match .
select vend_name from django_apps_vendor where vend_name regexp "\\." order by vend_name;
+--------------+
| vend_name |
+--------------+
| Furball Inc. |
+--------------+
This is the output we want . This processing is called escape . All characters with special meanings in regular expressions must be escaped in this way . Include :. | [ ] And other special characters used so far .
\\t \\r \\n \\f \\v : It means something different .
Mysql Two backslashes are required :\\ Mysql Explain one for yourself ,regexp Explain another by yourself .
Match character class :
Numbers , Letter , And numbers and letters .
[:alnum:]: Represents any letter or number (a-z A-Z 0-9).
[:alpha:] : Any letter
[:digit:] : Numbers
[:xdigit:]: Hexadecimal number (a-f A-F 0-9)
[:lower:]
[:upper:]
[:space:] : Any white space character (\\t \\r \\n \\f \\v)
[:cntrl:] ASCII Control characters (0-31 and 127)
[:blank:] : Spaces and tabs
Match multiple instances :
* ,+, ?,{n},{n,},{n,m}
0 One or more matches ,*
1 One or more matches +
0 Or 1 A match ?
A specified number of matches {n}
No less than the specified number of matches {n,}
The range of the number of matches {n,m ,m No more than 255}
select prod_name from django_apps_product where prod_name regexp "\\([0-9] sticks?\\)" order by prod_name;
+---------------+
| prod_name |
+---------------+
| TNT(1 stick) |
| TNT(5 sticks) |
+---------------+
\\([0-9] sticks?\\) :\\( matching ),[0-9],sticks? matching stick and sticks,? matching 0 A or a , send s Become optional ,
\\) matching )
my_firstDB> select prod_name from django_apps_product where prod_name regexp "[[:digit:]]{4}" order by prod_name;
+--------------+
| prod_name |
+--------------+
| JetPack 1000 |
| JetPack 2000 |
+--------------+
"[[:digit:]]{4}" : Match any number as 4 position
select prod_name from django_apps_product where prod_name regexp "[0-9][0-9][0-9][0-9]" order by prod_name;
+--------------+
| prod_name |
+--------------+
| JetPack 1000 |
| JetPack 2000 |
+--------------+
Locator :
^ $ [[:>:]] [[:<:]]
The text begins The end of the text , The beginning of words , Ending of words
select prod_name from django_apps_product where prod_name regexp "^[0-9\\.]" order by prod_name;
+--------------+
| prod_name |
+--------------+
| .5 ton anvil |
| 1 ton anvil |
| 2 ton anvil |
+--------------+
^ : Two meanings of :[^123] Denying
^[0-9\\.]: Indicates the beginning of the text .
like and regexp: Use locators (^ and $)like Can reach and regexp The same thing .
ordinary regexp test
select "hello" regexp "[0-9]";
+------------------------+
| "hello" regexp "[0-9]" |
+------------------------+
| 0 |
+------------------------+
0 Represents a mismatch ,1 On behalf of the match . Obviously hello There are no numbers in .
Chapter ten - Create fields
边栏推荐
猜你喜欢

硬件课程设计:基于STM32的多功能播放器之小说阅读

线程机制与事件机制

LeetCode精講——676. 實現一個魔法字典(難度:中等)

单向链表实现队列和栈

AMD RDNA 3 Navi 31旗舰GPU据称采用3D V-Cache封装以及最高384MB缓存

Leatcode Speech - 676. Implémenter un dictionnaire magique (difficulté: moyenne)

LeetCode精讲——1252. 奇数值单元格的数目(难度:简单)

迭代分形图形的绘制

unity2d移动细节官方案例练习

AVL tree - binary lookup tree with equilibrium condition
随机推荐
unity3d-记录案例小点
AIOps落地五大原则(三):架构路线
Drawing of iterative fractal graphics
Leetcode lecture - 1252 Number of odd cells (difficulty: simple)
SAP ABAP BAPI_ACC_DOCUMENT_POST 创建会计凭证
基于数组和节点的动态变化(增删改查)
简单说一下进程
Unity3d monobehavior base class
关于线程安全
LeetCode精讲——1252. 奇数值单元格的数目(难度:简单)
硬件课程设计:基于STM32的多功能播放器之MP3音乐播放
01. Write three listeners in a class
AVL树-带平衡条件的二叉查找树
For the approval of SQL changes, I set DBA approval. Why can't DBA see the list
Use the pointer to write a program to insert a character at any position of a string (the position of the inserted character is required to be input by the user from the keyboard).
我这边已经把101.132.179.94加到oracle的白名单里了,仍然ping失败,请问一下该怎
Unity2d fruit ninja case
Scope when multiple else if are nested
JS make dynamic small rocket
C#基础到入门(一篇就够了)