Python 02 Writing, Saving, and Running Your First Script

preview_player
Показать описание
#atharhashmisir #python
Writing Your First Python Script
a. Choose a Text Editor or IDE:

Text Editors: Examples include Notepad (Windows), TextEdit (Mac), or more sophisticated ones like Sublime Text or Atom.
Integrated Development Environments (IDEs): Examples include PyCharm, Visual Studio Code, or IDLE (which comes with Python).
b. Write Your Python Code:

Open your text editor or IDE.
Type in a simple Python script. For example, a classic "Hello, World!" script:
python
Copy code
print("Hello, World!")
2. Saving Your Python Script
a. Choose a File Name:

b. Save the File:

In your text editor or IDE, go to the “File” menu and select “Save As” (or just “Save” if you’re saving the file for the first time).
Choose a location on your computer where you want to save the file.
Make sure the file name ends with .py, and then click “Save”.
3. Executing Your Python Script
a. Open a Command Line Interface:

Windows: Open Command Prompt (cmd) or PowerShell.
Mac/Linux: Open Terminal.
b. Navigate to the Directory Containing Your Script:

Use the cd command to change directories. For example, if your script is in a folder called PythonScripts on your desktop, you would type:
bash
Copy code
cd Desktop/PythonScripts
c. Run Your Python Script:

Type python followed by the name of your script to execute it. For example:
bash
Copy code
Note: On some systems, you might need to use python3 instead of python to ensure you’re using Python 3. So it could be:
bash
Copy code
d. View the Output:

Copy code
Hello, World!
Summary
Writing: Use a text editor or IDE to write Python code.
Saving: Save the code with a .py extension.
Executing: Run the script via the command line to see the results.
This process is the foundation of working with Python scripts and is essential for coding and developing applications in Python.
Рекомендации по теме