1. Python Installation:
- Go to the official Python website (python.org) and download the latest version of Python suitable for your operating system (Windows, macOS, Linux).
- Run the installer and follow the on-screen instructions to complete the installation.
- Make sure to check the option to add Python to your system PATH during the installation. This will allow you to run Python from the command line.
2. Python Quickstart:
- Open your favorite text editor or IDE (Integrated Development Environment) to write Python code. Examples include Visual Studio Code, PyCharm, or IDLE (included with Python installation).
- Start your Python code with a
print
statement to display output. For example:pythonprint("Hello, Python!")
- Save your code with the
.py
extension, for example,hello.py
. - Open a terminal or command prompt and navigate to the directory where you saved the Python file.
- Run your Python script by typing
python filename.py
(replacefilename
with the actual name of your Python file) and press Enter.
3. Python Command Line:
- Open a terminal or command prompt on your computer.
- To check if Python is installed correctly, type
python --version
and press Enter. You should see the installed Python version. - To enter the Python interactive shell, simply type
python
and press Enter. You will see a prompt with three greater-than signs>>>
. - In the Python shell, you can write and execute Python code line by line. For example:python
>>> print("Hello, Python!")
- To exit the Python shell, type
exit()
or pressCtrl + D
(on macOS/Linux) orCtrl + Z
(on Windows).
Tips:
- Python is case-sensitive, so be careful with capitalization in your code.
- Use indentation (4 spaces recommended) to define code blocks instead of braces or keywords.
- Python comments start with the
#
symbol and are ignored by the interpreter.
These simple notes should help you get started with Python, from installation to running Python scripts via the command line. As you continue learning Python, explore more topics like variables, data types, control structures, and functions. Happy coding!
<< Previous Next >>