Python入门(一)数据类型、循环语句
腳本語言類型:
1.編譯型語言:寫完代碼不能執行,需要先編譯? ? ?eg:c、c++、c#
2.解釋性語言:不需要編譯 直接執行? ? ? ? ? ? ? ? ? ? ? eg:python、java、php、js、go、ruby
?
編程工具? pycharm
1.破解方法:https://blog.csdn.net/sophia_11/article/details/86520390? ?; idea.lanyus.com
2.創建 New project
create new project -》pure python? (選擇路徑)-》new-》python file
注:選擇existing interpreter 避免創建虛擬環境
?
3.修改python版本:
? ? ? ? ? ? ? ? ??
?
Python 數據類型
1.定義變量:? 變量名 = ‘變量值’
2.整數? int:Python可以處理任意大小的整數,當然包括負整數,在Python程序中,整數的表示方法和數學上的寫法一模一樣,例如:1,100,-8080,0,等等。
3.浮點數? float:浮點數也就是小數,之所以稱為浮點數,是因為按照科學記數法表示時,一個浮點數的小數點位置是可變的,比如,1.23x10^9和12.3x10^8是相等的。
4.字符串? string:字符串是以''或""括起來的任意文本,比如'abc',"xyz"等等。
5.布爾值:布爾值和布爾代數的表示完全一致,一個布爾值只有True、False兩種值,要么是True,要么是False,在Python中,可以直接用True、False表示布爾值(請注意大小寫),也可以通過布爾運算計算出來。
6.空值? None:空值是Python里一個特殊的值,用None表示。
?
Python print語句
1.print語句:eg:print ('hello,word')
注:python3 強制使用('hello,word')格式,python2可以使用'hello,word'格式
2.特殊語句: print ('''? let's go "a b"? ''')
?
Python 注釋方法
1.單行注釋:#print ('hello,word')
2.批量注釋:'''? ? ? ? ?'''? 或者? """? ? """
?
Python? input用法
?1.input 語句: name = input ("請輸入用戶名).strip()? ? ? <-去除空格
?
?
Python條件判斷和循環
?
1.if條件判斷:(相等==,不相等!=,大于等于>=,小于等于<=)
age = 20
if age >= 18:print 'your age is', ageprint 'adult'
print 'END'
2.if .. else
if age >= 18:print 'adult' else:print 'teenager'
3. if .. elif ..else
if age >= 18:print 'adult' elif age >= 6:print 'teenager' elif age >= 3:print 'kid' else:print 'baby'
4.for 循環
L = ['Adam', 'Lisa', 'Bart'] for name in L:print name
5.while循環
N = 10 x = 0 while x < N:print xx = x + 1
6.break退出
sum = 0 x = 1 while True:sum = sum + xx = x + 1if x > 100:break print sum
7.continue繼續
L = [75, 98, 59, 81, 66, 43, 69, 85] sum = 0.0 n = 0
for x in L:if x < 60:continuesum = sum + xn = n + 1
轉載于:https://www.cnblogs.com/chenduxiu/p/10621089.html
總結
以上是生活随笔為你收集整理的Python入门(一)数据类型、循环语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 三星堆博物馆游玩攻略
- 下一篇: Linux安装Nodejs