<jupyter_start><jupyter_text>Python 基礎語法熟悉(1) - print, 取值, def![Q1.2](images/HW_Q1-2.jpg)  print`print(str_1, srt_2, ..., sep='分隔字串', end='結尾字串')`會輸出str_1分隔字串srt_2分隔字串...結尾字串<jupyter_code>print("1"); print("2")          # 預設換行輸出
print("1", end=" "); print("2")  # 更改預設結尾變成空格
print("1", "2", sep=' ', end='\n') # 用 sep 在兩個中間加入空白<jupyter_output>1 2<jupyter_text>取值語法<jupyter_code>str1 = '123456789'
str2 = 'abcdefghij'
print(str1[0:])  # 即 print(str)
print(str1[:-1]) # 去掉最後一個字符
print(str1[1:])  # 去掉第一個字符
print(str1[0])   # 取第一個字符(注意跟str1[0:]的起頭一樣)
print(str1[-1])   # 取倒數第一個字符(注意跟str1[:-1]的結尾不同)
print(str1*2)    # 重複兩次
print(str1+str2) # 合併兩者<jupyter_output>123456789abcdefghij<jupyter_text>自訂義函數 以4捨5入函數為例<jupyter_code>def my_round(x, n=0):
    "Sefl written round function"
    xn_str = str(x * 10 ** n + .5)
    x_round = float(xn_str[:xn_str.find('.')]) / (10**n)
    return x_round<jupyter_output><empty_output><jupyter_text>測試輸出<jupyter_code>print(my_round(4321.1234)) # 預設4捨5入到整數
print(my_round(4321.1234, 1)) # 4捨5入取到小數第一位
print(my_round(4321.1234, -1)) # 4捨5入取到十位<jupyter_output>4320.0
{'fraction_non_alphanumeric': 0.1954337899543379, 'fraction_numerical': 0.091324200913242, 'mean_word_length': 6.306666666666667, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '261735', 'license': 'Unlicense', 'n_tokens_mistral': 684, 'n_tokens_neox': 687, 'n_words': 65, 'path': '20190225 NCTS AI MATH - HW1_2.ipynb', 'repo_name': 'PeterHsi/NCTS2019-AI-MATH-by-HWP', 'size': '1095'}