程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Explain how Python works

編輯:Python


python There are two modes of operation : Interactive and scripted . Interactive can be through cmd Command line window or IDEL Realization , And scripted by writing a script (.py Closing document ) Realization . among Interactive is mainly used for simple python Run or test debugging python When used , Scripting is running python The main method of program .

1  Execute... In interactive mode  Python

In this mode, there is no need to create script files , Directly in  Python Write the corresponding... In the interpreter's interaction mode  Python  Sentence can be used .

1.1 Windows Command line tools

adopt Windows Command line tools for interactive running python. Find... On the start menu “ Command prompt ”, open , Go to command line mode , Or press  “win +R”  key , start-up “ function ”, stay “ function ” Input in  cmd  And then go back , The command line tool pops up , Then input python Enter to start Python Interpreter , The following interface appears .
Then type... At the command prompt print('Hello world!'), Then press enter to output “Hello world!”. Interactive mode : Write a line of code , And python Interact once ,python Do it once .


1.2 IDEL Interactive operation python

adopt IDEL Interactive operation python. from “ Start ” Find Python->IDEL, Here's the picture .

start-up IDEL after , The same input print('Hello world!'), Then press enter to output “Hello world!”. Also type a line of code , And python Interact once ,python Do it once . It's just IEDL in python The code can highlight .

2  Scripted execution Python

2.1  Write a script file with a text editor

Through text editor , Write a script file , Name it  test.py, as follows :

Then in command line mode cd To test.py File path , Then input  python test.py  You can enter. , as follows :



  Note the path of the script file , If the current working path and script file are not in the same path , To enter   The path of the script file , Or give the full path of the script file .

2.2 IDEL Write script files in

stay IDEL Click on the file->new file, An unnamed... Will pop up (Untitled) Script window , Then enter the following code , And press Ctrl+S Save as  test.py .num = int(input(' Please enter an integer : '))
#  Output  1 - num( contain )  All primes in
for i in range(2,num+1):
 fg=0
 for j in range(2,i-1):
 if i%j ==0:
 fg=1
 break
 if fg==0:
 print(i)


Press F5 Run saved  test.py  Script , The following interface will appear  

3  Interactive and scripted comparison

  • Run in interactive mode python sentence , It will automatically print out the calculation results ; The way of script file will not .
  • Run in interactive mode python sentence , Every input statement will not be saved , After exiting the interactive environment, it will disappear , But you can save all the statements through the script file .

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved