随笔分类 - python
摘要:1、>>> a = ["aa","bb","cc","dd"] ## 生成列表 >>> a ['aa', 'bb', 'cc', 'dd'] >>> a = [] ## 清空列表 >>> a []2、 >>> a = ["aa","bb","cc","dd"] ## 生成列表 >
阅读全文
摘要:>>> a = list(range(1,21)) ## 生成列表 >>> a [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> a[::2] ## 提取第奇数元素 [1, 3, 5, 7, 9,
阅读全文
摘要:>>> a = list(range(1,21)) ##生成列表 >>> a [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] >>> a[:10] ## 提取前10个元素 [1, 2, 3, 4, 5,
阅读全文
摘要:1、 >>> a = ["aaa","bbb","ccc","ddd"] >>> b = reversed(a) >>> c = [] >>> for i in b: c.append(i) >>> c ['ddd', 'ccc', 'bbb', 'aaa'] 2、 >>> a = ["aaa","
阅读全文
摘要:1、 aaa = "123" answer = input("please input the answer:") while True: if answer == aaa: break answer = input("please input the answer,again:") print("
阅读全文
摘要:1、for 循环 >>> sum = 0 >>> for i in range(101): sum += i >>> print(sum) 5050 2、while循环 >>> sum = 0 >>> i = 0 >>> while i <= 100: sum += i i += 1 >>> pri
阅读全文
摘要:1、 # prize test age = 20 score = "A" if age < 18: if score == "A": print("congratulations!!!") else: print("score not A!!!") else: print("age excess 1
阅读全文
摘要:1、assert可以植入程序中进行程序检查 >>> a = 5 >>> b = 3 >>> assert a > 0 >>> assert a < 0 Traceback (most recent call last): File "<pyshell#279>", line 1, in <modul
阅读全文
摘要:1、 #guess integer game import random secret = random.randint(1,10) temp = input("please input an integer:") guess = int(temp) times = 1 while (guess !
阅读全文
摘要:1、 >>> import random >>> random.randint(1,5) 1 >>> random.randint(1,5) 4 >>> random.randint(1,5) 3 >>> random.randint(1,5) 2 >>> random.randint(10,20)
阅读全文
摘要:>>> tag = True >>> test1 = {} >>> type(test1) <class 'dict'> >>> while tag: name = input("please input your name: ") mountain = input("which mountain
阅读全文
摘要:1、 >>> test1 = ["aa","bb","aa","cc","aa","cc","dd","ee"] >>> test1 ['aa', 'bb', 'aa', 'cc', 'aa', 'cc', 'dd', 'ee'] >>> "aa&
阅读全文
摘要:1、 >>> a = {} >>> while a != "quit": a = input("please input an incredient:") if a != "quit": print(f"{a} will be added!!") please input an incredient
阅读全文
摘要:>>> while True: a = input("please input something:") if a == "ab": break else: print(f"you had input {a}.") please input something:100 you had input 1
阅读全文
摘要:1、 >>> tag = True >>> while tag: a = input("please input something : ") if a == "quit": tag = False else: print(a) please input something : 100 100 pl
阅读全文
摘要:1、 >>> a = "" >>> while a != "quit": a = input("please input a str or 'quit' to leave: ") print(a) please input a str or 'quit' to leave: 100 100 plea
阅读全文
摘要:>>> for i in range(1,11): if i % 4 == 0: print(i) 4 8 >>> for i in range(1,11): if i % 4 == 0: break print(i) 1 2 3 >>> for i in range(1,11): if i % 4
阅读全文
摘要:1、 >>> i = 1 >>> sum = 0 >>> while i <= 100: sum = sum + i i = i + 1 ## 当此处i等于101时循环停止 >>> print(sum) 5050 2、 >>> a = 100 >>> b = int(input("please in
阅读全文
摘要:1、 >>> test1 = dict(key1="aaa",key2="bbb",key3="ccc",key4="ddd") >>> test1 {'key1': 'aaa', 'key2': 'bbb', 'key3': 'ccc', 'key4': 'ddd'} >>> del test1[
阅读全文
摘要:1、 >>> a = dict(zip(["one","two","three"],[100,200,300])) >>> a {'one': 100, 'two': 200, 'three': 300} >>> b = a >>> b {'one': 100, 'two': 200, 'three
阅读全文

浙公网安备 33010602011771号