learn python the hard way,老男孩python第一天筆記

 2023-11-07 阅读 30 评论 0

摘要:1、變量 ? 把結果存下來,變量存在內存里,name1 = "hepeng" ? ?name2=name1 ? name1 = "hp" ? ?print(name1,name2)   name2是name1在內存中的指向相當于軟連接,輸出結果,name1=hp ?name2=hepeng 2、字符編

1、變量 ? 把結果存下來,變量存在內存里,name1 = "hepeng" ? ?name2=name1 ? name1 = "hp" ? ?print(name1,name2)

  name2是name1在內存中的指向相當于軟連接,輸出結果,name1=hp ?name2=hepeng

2、字符編碼都是向下兼容的,unicode萬國碼,utf8 存英文1byte 存中文3byte

3、用戶交互程序,username = input("請輸入")

  變量引用格式化輸出,%s字符串,%d只能接受數字,%f浮點小數

 name = hpinfo= "Name:%s"  %  (name)print(info)

learn python the hard way。  字符串轉 整形 int ?整形轉字符串str

  用format格式化 輸出

  

name = "hp"info2 = "Name:{_name}".format(_name = name)print(info2) 

?

 

4、密碼密文使用getpass

python筆記。  import getpass

  password = getpass.getpass("password:")  ? getpass ?在pycharm里不好使,在命令行可以

5、if else循環,用戶名密碼匹配輸出ok,不匹配輸出wrong

if  username == user and  password = pwd :print("ok")else:print("wrong")

?

?

6、while循環,年齡猜三次,正確就退出,三次不對給提示

 count = 0 age = 23while  count <3:guess_age = int(input("guess age"))if guess_age == age:print("you got it")breakelif guess_age > age:print("too bigger")else:print("too smaller")count +=1
else:print("you have try too many choice")

python爬蟲。?

  

7、for 循環?

等同上邊while代碼,用for循環實現age猜三次

age = 23for i in range(3):guess_age = int(input("guess age"))if guess_age == age:print("you got it")breakelif guess_age > age:print("too bigger")else:print("too smaller")
else:print("you have try too many choice")

for i in range(0,10,3) 0-10隔三個

8、continue跳出本次循環進入下一次循環,break結束整個循環

for i in range(10):if  i  < 3:print("loop",i)else:continueprint("hehe")

python有什么用、當i循環到3的時候就不執行print了,continue直接跳出本次循環進行下次循環

for i in range(10):if  i  < 3:print("loop",i)else:breakprint("hehe")

當i循環到3的時候直接跳出循環,不在執行,兩個的輸出結果是一樣的,但是原理不同

    

?

?

?

python3??

?

?

?

?

?

python筆記全??

?

     

轉載于:https://www.cnblogs.com/hepeng123/p/6530390.html

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

原文链接:https://hbdhgg.com/4/167235.html

发表评论:

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

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

底部版权信息