日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python概念英文版_和我一起学python,基本概念 (life is short ,we need python)

發布時間:2024/9/30 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python概念英文版_和我一起学python,基本概念 (life is short ,we need python) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

作者:tobecrazy ?出處:http://www.cnblogs.com/tobecrazy 歡迎轉載,轉載請注明出處。thank you!

基本概念 :

常量:

常量名全部大寫,如PI

變量:

python沒有變量類型,也不必聲明,直接賦值即可.?變量可以是數字,字符串,布爾值(True,Flase,注意大小寫),列表,字典等類型.

如: var=1 str='hello'

變量名:

字母數字下劃線,不能以數字開頭。全局變量最好全部大寫,一般變量注意避免保留字。

有效變量名: test123 _68 py

字符串:

在雙引號中的字符串與單引號中的字符串的使用完全相同.

如:'this is a test'=="this is a test"

三引號'''/"""

利用三引號,你可以指示一個多行的字符串。你可以在三引號中自由的使用單引號和雙引號,三引號可以做為多行注釋。

''' what's your name ?

my name is Young'''

轉義字符,如果要輸出' "等有特殊意義的字符,需要將其轉義才能輸出

\' \" 引號 \n 換行

如:"Jason:\"what's your name?\"\nYoung:\'my name is Young\' "

此外轉義字符也有跨行鏈接符的作用

如:

"Jason:\"where are you from\"\n\

Young:\'I come from China\' "

如果你想要指示某些不需要如轉義符那樣的特別處理的字符串,那么你需要指定一個自然字符串。自然字符串通過給字符串加上前綴r或R來指定。例如r"Newlines are indicated by \n"。

代碼如下:

1 #!/usr/bin/python

2 '''

3 this is a Python script4 create by Young5 2014-06-286 '''

7 var=3.14

8 str='this is a python string'

9 printvar10 printstr11 _123="this is variable _123"

12 print_12313 print '''what's your name ?14 my name is Young'''

15 print "Jason:\"what's your name?\"\nYoung:\'my name is Young\'"

16 print "Jason:\"where are you from\"\17 \nYoung:\'I come from China\'

18 print r"\"what's your name?\"\n"

輸出結果為:

3.14

this is a python string

this is variable _123

what's your name ?

my name is Young

Jason:"what's your name?"

Young:'my name is Young'

Jason:"where are you from"

Young:'I come from China'

\"what's your name?\"\n

總結:python變量和常量和別的編程語言基本相同,字符串有自己的特色,雙引號和單引號效果相同,三引號可以作為python的注釋,轉義字符能當做跨行連接符使用,使用r/R可以是轉義字符失去作用。

運算符:

常用運算符+ - * / ** //?% << >> > < >= <= & ^ ~ == != not and or

比較常見的運算符和其他編程語言一樣,只有** //比較特殊

** ? ? ?表示冪運算 ?x**y?返回x的y次冪 ? 如2**3 得出8

// ? ? ? 表示取整除 ?x//y得到整數部分 如 5//3 返回1

1 #!/usr/bin/python

2 '''

3 this is a Python script4 create by Young5 2014-06-286 '''

7 PI=3.14

8 r=10.0

9 area=PI*r**2

10 print "PI*r**2 is",area11 x=19

12 y=5

13 print "4**0.5 is",4**0.5

14 print "y//x is",y//x15 print "x//y is", x//y

運行結果:

PI*r**2 is 314.0

4**0.5 is 2.0

y//x is 0

x//y is 3

結論:當使用** ,如果第二個字符為0.5,意味著開平方;如果是負數-2,意味著倒數2次冪

使用// ,如果第一個數大于第二個數,返回整數商,如果小于返回0

python + 妙用

合并list可以直接使用加

a = [1, 2, 3]

b = [4, 5, 6]

print a +b

#prints [1, 2, 3, 4, 5, 6]

python *妙用

重復輸出list可以使用*

print ["O"] * 5willprint out ['O', 'O', 'O', 'O', 'O'],

總結

以上是生活随笔為你收集整理的python概念英文版_和我一起学python,基本概念 (life is short ,we need python)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。