標籤:格式 input inline ref unicode編碼 大寫 3.x round image
為什麼要學習Python?
Python擅長的領域
1. python2.x中不支援中文編碼,預設編碼格式為ASCII碼,而python3.x中支援Unicode編碼,支援中文,變數名可以為中文,如:年齡=19(但不建議這麼做)。
2. python中定義常量:把變數名全部大寫 如:PIE=3.14
3.編碼格式的演變:
4.python 中的互動性輸入:
import getpass #匯入關於密文的模組
username=input(“your name:”)
age=input(“your age: ”)
#password=input(“set your password: ”)
password=getpass.getpass(“set your password :”)
print(“info:” ,username,age,password)
5.Python中的多行輸出或者多行注釋(字串的拼接)
(1)’’’ ‘’’ 三引號可以表示多行注釋
’’’ this is a program for you
and you will get help from here,
click this button’’’
(2)三引號的值(多行)也可以賦給一個變數使用
info=’’’ hello World,
name=wujian
age=22
hello!!!”’
print(info)
(3)”’ "’用於多行的格式化輸出
username=input(“your name: ”)
age=input(“your age: ”) #age=int(input(“your age: ”))將字元類型轉成數字類型,同理也可以使用str()函數將其他的轉成字串類型。
salary=input(“you salary: ”)
info=”’ -------------------info of %s-------------
Name:%s
age:%s
salary:%s
”’ %(username,username,age,salary)
# %s為預留位置,後面的變數要依次對應預留位置。類似的還有%d表示輸出為數字number, %f表示為浮點小數
print(info)
或者:
info2=”’ -------------------info of {_name}-------------
Name:{_name}
age:{_age}
salary:{_salary}
”’ .format(_name=username,_age=age,_salary=salary)
print(info2)
再或者
info3=”’ -------------------info of {0}-------------
Name:{0}
age:{1}
salary:{2}
”’ .format(username,age,salary)
# {數字}與後面的變數要依次對應
print(info3)
6.猜年齡遊戲:允許嘗試猜測5次的機會,如果還猜不中,就提示“你已經嘗試多次了,滾開fuck off”
改進版:玩了三次還沒有猜中,會提示是否繼續玩下去
7.關於for迴圈:
for i in range(10):
print(“loop:” ,i)
for j in range(1,100,2)#1-100,間隔為2,輸出的全為奇數
print(“loop: ” ,i)
8. continue:結束本次迴圈,倒回去繼續執行下一次迴圈
break:跳出整個迴圈
9.作業
第一周day1Python學習筆記