python 基本語句

來源:互聯網
上載者:User

標籤:woe   字串格式化   oct   bsp   int   for   基本   put   bre   

print(‘‘‘ 

hello word

‘‘‘)

hello word 

 

print (" hello \nwoerd")

hello

woed

 

print("hello \\nword ")

hello \nword

 

print (r"hello word\n")

hello work\n

 

a="dogs"

print ("hello %s" %a)

hello dogs

 

a=123

print("hello %d " %a)

heelo 123

 

a=123

print ("hello %i" %a)

hello 123

 

字串格式化

a=123

printf (hello %d " %a)

hello 123

 

a=123

print("hello %i " %a)

hello 123 

 

a=123

print ("hello %s " %a)

hello 123

 

運算子

10%20

10

 

2**8

256

 

12>>2

3

 

12>>3

1

 

 

進位轉換

二進位轉換

a=123

b=bin(a)

print(b)

ob1111011

 

a=123

b=oct(a)

print (b)

0o173

 

a=123

b=hex(a)

print(b)

 ox7b

 

轉換二進位

a=‘0b1111011‘

b=int (a,base=2)

print (b)

123

 

a=‘ob1111011‘

b=int(a,base=2)

c=oct(b)

print(c)

0o173

 

八進位轉換

a=‘0o173‘

b=int(a,base=8)

print(b)

123

 

a=‘0o173‘

b=int(a ,base=8)

c=bin(b)

print(c)

ob1111011

 

a=‘0o173‘

b=int (a,base=8)

c=hex(b)

print(c)

ox7b

 

 

a=123

a=b=c=456

print(a,b,c)

456 456 456

 

if 3>4

  print("牛逼")

else;

print ("不牛逼")

不牛逼

 

a=input(“請輸入的數字”)

print(“輸入的數字 %s " %a)

請輸入的數字123

輸入的數字123

 

求100內的奇數之和 偶數之和

odd=0 

oven=0 

for i in range (1,101):

if 1%2:

odd=odd+i

else:

oven=oven+i

print(odd)

print(oven)

 

二分法實現

a=input("請輸入一個五位元:")

a=int (a)

if a > 99:

  if a > 9999:

  print("5位元")

 if a > 999

print("4位元")

else:

print("3位元")

else:

 print("2位元") if a > 9 else print ("1位元")

 

list range(1,20,2)

1,3,5,7,9,11,13,15,17,19

 

### continue,,執行continux之後,立刻執行本次迴圈後面的

for  i in range (5)

if i ==3

prinf(i)

0   1   2   4  5

 

###break,,執行了break之後表示跳出迴圈,迴圈終止

for i in range (10):

if i  == 4 :

break 

print(i)

0  1  2  3  4

python 基本語句

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.