python編程入門,python的基礎_python基礎知識,python必背內容,一、python的基

 2023-10-04 阅读 30 评论 0

摘要:python基礎知識,python必背內容,一、python的基 一、python的基礎 1、簡單寫一行python代碼:print(‘hello,world’)print(‘你好,北京’) 2、變量:name="劉夢雅"print(name) 程序

python基礎知識,python必背內容,一、python的基

一、python的基礎

1、簡單寫一行python代碼:print(‘hello,world’)print(‘你好,北京’)

2、變量:name="劉夢雅"print(name)

程序交互:name=input“請輸入你的名字”print(name)

python編程入門?3、數據類型

(1)int,long類型:a=2*20print(a,type(a))

(2)字符串類型str:name=input(‘請輸入你的名字‘)print(name,type(name))()

(3)布爾類型:print(true,type(true))

4、if語句choice=input(‘請輸入你猜的數字’)if choice==‘2’ print(‘我請你吃飯’)else print(‘你請我吃飯’)

5、while語句

python語言程序設計,flag = true;count =1;while flag: print(count);

6、break語句:count=1while true: print(count) count=count+1 if count==101 break

7、continue語句count=0 while count<10; count =count +1if count ==7;continue ;print(count )

8、in not in的用法:comment =input(‘請輸入你的評論’) if ‘傻子’ in comment: print (‘您輸入的為敏感詞匯,請重新輸入’)

9、while else

14415H512-0.gifcount = 1while True: print (count ) if count == 3:break count +=1else print(‘循環正常‘)

14415H512-0.gif

輸出 1

python爬蟲教程,2

3

14415H512-0.gifcount =1flag = Truewhile flag : print (count) if count == 3: flag=False count+=1else : print (‘循環正常完畢‘)

14415H512-0.gif

輸出:1

2

3

循環正常完畢

python和java,10、格式化輸出:

1)第一種name=input(‘請輸入你的名字:’)age =input(‘請輸入你的年齡:’)hobby=input(‘請輸入你的愛好:’)ms =‘我叫%s,今年%d,愛好是%s’ % (name,int(age),hobby)print(ms)

2)第二種dic = {‘name’:‘oldboy‘,‘age‘:15,‘hobby‘:‘踢足球‘}msg=‘我叫%(name)s,今年%(age)d,愛好是%(hobby)s’ % dicprint(msg)

3)第三種

再格式化輸出中單純的顯示% 用%%解決name=input(‘請輸入你的名字:’)age =input(‘請輸入你的年齡:’)msg=‘我叫%s,今年%d,學習進度為1%%’ % (name,int(age))print(msg)

11、運算符print(int(True))print (int(False)) 輸出:1 0 Trueprint(bool(100))

python有什么用。and or notprint (1 or 3) 輸出 1print (1 and 3 ) 3print (0 or 2) 2print(0 and 2) 0print (1>2 or 3 and 4) 4

python基礎知識

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/113636.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息