一 python程式設計核心知識點

2021-10-07 14:25:06 字數 3372 閱讀 2133

1、互動模式和檔案模式

2、變數型別、輸入和輸出

整數、小數、字串、複數、列表、元組、字典、集合

int、float、str、complex、list、tuple、dict、set

>>> a=3

>>> type(a)

>>> b=1.0

>>> type(b)

>>> s='abc'

>>> type(s)

>>> d=1+2j

>>> type(d)

>>>l=[1,2,'a']

>>> type(l)

>>>t=(1,2,3)

>>> type(t)

>>> t=(a,b,c)

traceback (most recent call last):

file "", line 1, in

nameerror: name 'c' is not defined

>>> type(t)

>>> t=('a','b','c')

>>> type(t)

>>> dt=

traceback (most recent call last):

file "", line 1, in

nameerror: name 'c' is not defined

>>> dt=

>>> type(dt)

>>> s=set([1,2,3])

>>> type(s)

>>> content = input("請輸入你的年齡:")     #不管輸入的是什麼內容,都是儲存為str型別

請輸入你的年齡:5

>>> print(content)

5>>> type(content)

3、isinstance、型別轉換

>>> s=set("123456")

>>> type(s)

>>> isinstance(s,int)

false

>>> isinstance(s,set)

true

>>> isinstance(s,float)

false

整數--->小數

整數--->字串

小數--->整數

小數--->字串

字串--->整數

整數--->小數

>>> float(1)

1.0>>> str(1)

'1'>>> int(1.1)

1>>> str(1.1)

'1.1'

>>> int('123')

123>>> float(''123)

file "", line 1

float(''123)

^syntaxerror: invalid syntax

>>> float('123')

123.0

4、if elif else

練習題:做乙個判斷,輸入一門成績,如果90分以上就是優秀。80到90之間良好,80以下為一般

>>> content=input("請輸入你的成績:")

請輸入你的成績:88

>>> if int(content)>=90:      #行業標準:縮排預設4個空格

...     print('優秀')

... elif 90>int(content)>=80:

...     print("良好")

... else:

...     print("一般")

...良好

>>> content=input("請輸入你的成績:")

請輸入你的成績:99

>>> if int(content)>=90:

...     print('優秀')

... elif 90>int(content)>=80:

...     print("良好")

... else:

...     print("一般")

...優秀

>>> content=input("請輸入你的成績:")

請輸入你的成績:0

>>> if int(content)>=90:

...     print('優秀')

... elif 90>int(content)>=80:

...     print("良好")

... else:

...     print("一般")

...一般

5、for 和 while

遍歷思想: for 和 wihle

>>> for a in range(10):

...     print(a)

...012

3456

789>>> list(range(10))

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

>>> tuple(range(10))

(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

>>> i=0

>>> while i<=9:

...     print(i)

...     i=i+1

...012

3456

789

6、單一布林值什麼時候是false?

0、' ' 、[ ] 、() 、 、''' ''' 、 """ """

>>> bool(0)

false

>>> bool('')

false

>>> bool('''''')

false

>>> bool("""""")

false

>>> bool()

false

>>> bool(())

false

>>> bool({})

false

其他一般都是true

2>1 true

2>3 false

7、練習題:用遍曆法,計算出a="123abc"中有幾個數字

a="123098ab6383cc"

result=0

for i in a:

if i in "1234567890":

result+=1

print(result)

python程式設計的核心知識點總結

我想要python實現,這已經不是什麼秘密了。webassembly它不僅會讓python進入瀏覽器,而且事實是兩者都是ios和安卓支援將j ascript作為應用程式的一部分執行,它還可以讓python進入移動平台。這一切都讓我興奮。但是當想到建立python的新實現這一艱鉅任務時,我的大腦也開始...

Eureka核心知識點

一 eureka特性 1.當註冊中心掛了,客戶端之間依然可以通過原有的登錄檔進行呼叫 註冊中心重啟後,客戶端會繼續註冊進來 2.當服務提供者掛了,在關閉自我保護的情況下,註冊中心在規定時間 預設是60s 內移除客戶端 關閉eureka註冊中心的自我保護模式,配置如下 eureka server en...

Eureka核心知識點

一 eureka特性 1.當註冊中心掛了,客戶端之間依然可以通過原有的登錄檔進行呼叫 註冊中心重啟後,客戶端會繼續註冊進來 2.當服務提供者掛了,在關閉自我保護的情況下,註冊中心在規定時間 預設是60s 內移除客戶端 關閉eureka註冊中心的自我保護模式,配置如下 eureka server en...