python學習筆記8

2021-07-04 21:38:43 字數 505 閱讀 6133

主要講了python的輸入和輸出

python通過[python2.x]raw_input和[python3.x]input來實現輸入輸出。

input可以加引數,表示為提示符,返回值為你的輸入。

比如:

age = input("how old are you?")

print ("your age is %s", age)

how old are you?12

your age is %s 12

print可以通過end引數去除輸出末尾的回車,換上end="??"中賦的末尾符號

比如:

print ("how old are you?", end=": ")

age = input();

print ("your age is %s", age)

how old are you?: 23

your age is %s 23

Python學習筆記8(類)

8.1 建立和使用類 class dog def init self,name,age 初始化屬性name和age self.name name self.age age defsit self 模擬小狗被命令石蹲下 print self.name is now sitting def roll s...

Python學習筆記8 語句

條件語句 有的程式裡寫的是 usr bin python,表示 python 直譯器在 usr bin 裡面。但是,如果寫成 usr bin env,則表示要通過系統搜尋路徑尋找 python 直譯器。不同系統,可 能直譯器的位置不同,所以這種方式能夠讓 更將擁有可移植性。usr bin env p...

python學習筆記8 format

format 是python的內建函式,主要用來控制輸出的格式,format 函式返回的是乙個string。format 函式的格式是 format spec fill align sign 0 width precision type fill align sign width integer p...