python第一次學習

2021-09-19 10:45:55 字數 2159 閱讀 8525

新增摘要           ## **的作用
(人機互動的方式與工具,注釋方便人們理解**的含義,機器不看)

print語法的作用

輸入

print("i love python") #列印內容

print("1+2")#print括號內不加引號與加引號有所區別

print(1+2)

輸出

i love python

1+23

機器你會執行注釋的內容

注釋一般用自然語言書寫

注釋的寫法

變數命名可以包含數字,大小寫字母,下劃線或者更多

out1=1

print(out1)

1out=1

輸出

1

syntaxerror: invalid syntax

p=1
p=a=1
a,s,d=1,2,3
a=9+2

print(a)

b=9-2

print(b)

c=8*9

print(c)

#python除法分為普通除法,地板除,取餘#

#普通除法

d=9/2

print(d)

#地板除

e=9//2

print(e)

#取餘f=9%2

print(f)

#兩個乘號就是指數

g=4**2

print(g)

輸出

11

7 72

4.54

1 16

2.比較或者關係運算子

-對兩個內容進行比較的運算子

-結果一定是布林值,即ture/false

輸入

#等於==

a=3==4

print(a)

#不等於!=

a=3!=4

print(a)

#其他符號

#>=,<=,<,>

輸出

false

true

3.賦值運算子

-把值放到變數中去(優先順序低)

輸入

#賦值符號=

a=9print(a)

#複雜賦值

a=b=9

print(a,b)

a,b=1,9

print(a,b)

#賦值的縮寫

c=c+3

print(c)

輸出

9

9 91 9

nameerror: name 'c' is not defined

4.邏輯運算子

-對布林值型別變數或者值進行運算的符號

-and:邏輯與

-or:邏輯或

-not:邏輯非

-python的裡面的邏輯運算沒有異或

-運算規則

-and看作乘法,or看作加法

-ture看作1,false看作0

-邏輯運算能轉換成整數數**算

-最後結果是0為false,否則為ture

#邏輯表示式舉例 

a=true

b=true

c=false

aa=a and b #左邊可以轉換為1*1

print(aa)

#布林值跟數字的轉換

#數字轉換成布林值的時候,0=false,其餘為true

#布林值轉換為數字時,true=1,false=0

#短路問題案例

a=true

b=true

c=false

aa=a or b and (a and c)

print(aa)

輸出

true

true

5.位運算子

6.成員運算子

7.身份運算子

第一次學習

printf 函式和 scanf 函式分別為輸出和輸入函式兩個函式都使用格式字串和引數列表。printf函式列印資料的指令要與待列印資料的型別相匹配。在 和轉換字元中間插入修飾符可修飾基本的轉換說明 scanf函式是輸入函式,它把輸入的字串轉換為整數 浮點數 字元或字串,而printf函式正好與他相...

第一次python筆記

1.注意raw input在python3.0中已經消失了 2.python3.0中的字串全部是unicode字串 3.關於原始字串的幾行 str c nnihao str c nnihao print str c nihao print r c nnihao c nnihao r r c nnih...

python第一次作業

1.輸入年 月,輸出本月有多少天 1.輸入年月 year int input year month int input month 2.判斷是那個月 if month 4 or month 6 or month 9 or month 11 print 30天 3.判斷是不是閏年,閏年2月29天,平年...