msg="hello1 hello2 hello3 " print(msg)
顯示結果為:
#? "? "只能進行單行的字符串
?
多行字符串用'''? ?''',前面設置變量,可以用'''? ?'''表示多行
msg='''hello1 hello2 hello3 ''' print(msg)
顯示結果為:
當然如果沒有設置變量,就相當于起到多行注釋的作用。(單行注釋用#號)
#msg="helloworld" msg='helloworld' #在python里“” ‘’ 是一樣的,在比如shell就表示不一樣的print(msg)
但是兩者的區別在于:
msg="hello‘world" #在字里面如果有一個單引號,那么就只能用雙引號,如果用單引號,那么msg='hello'world',
系統會認為‘hello’是一個,后面就會認為是變量。實質上我們想要的是hello’world msg=’hello"world’ #在字里面如果有一個雙引號,那么就只能用單引號 msg='''hell"o'world''' #在字里面如果單引號、雙引號都有,那么就用三引號print(msg)
?
pycharm使用
??? 集成開發環境(IDE,Integrated Development Environment )
??? VIM #經典的linux下的文本編輯器
??? Emacs #linux 文本編輯器, 比vim更容易使用
??? Eclipse # Java IDE,支持python, c ,c++
??? Visual Studio # 微軟開發的 IDE, python,c++,java,C#
??? notepad++ ,
??? sublime python開發的
??? Pycharm ,是主要用于python開發的ide
?
字符串的格式化輸出: %s s=string %d d=digit 整數 %f f=float 浮點數,約等于小數
?
?
自動創建作者和日期
?
輸出這種格式:
---------info of name---- Name:name Age:age Job:job Salary:salary you will be retired in %s years --------------end---------
?
name=input("Name:") age=int(input("Age:")) job=input("Job:") salary=input("Salary:") #此時如果加字符串如“300的”,加int就沒有用 if salary.isdigit(): #長的像不像數字,比如200d(不像),“200”(像,只不過是字符串)salary = int(salary) # else: # print("must be digit") # exit("must be digit")替換這行和下行 # exit()msg=''' ---------info of %s----- Name:%s Age:%s Job:%s Salary:%f you will be retired in %s years --------------end--------- '''%(name,name,age,job,salary,60-age) print(msg)#%f(浮點數) %d (數字)
下面完成一些設置達到完成這種下面顯示的預設,具體方法如下:
#__author: hasee #date: 2017/11/26
?
?