Creating Python Files and Variables
Creating a Python File
To create a Python file, you'll need to:
1. Open a text editor (such as Sublime Text, Atom, or Notepad)
2. Write your Python code
3. Save the file with a .py extension
For example, you might create a file called hello.py with the following code:
print("Hello, world!")
To run the file, open a command prompt or terminal window, navigate to the directory
where the file is saved, and enter the name of the file (including the .py extension).
Importing a Python File
To import a Python file into another program, you'll need to use the import statement,
followed by the name of the file (without the .py extension). For example:
import hello
Creating a Python File
To create a Python file, you'll need to:
1. Open a text editor (such as Sublime Text, Atom, or Notepad)
2. Write your Python code
3. Save the file with a .py extension
For example, you might create a file called hello.py with the following code:
print("Hello, world!")
To run the file, open a command prompt or terminal window, navigate to the directory
where the file is saved, and enter the name of the file (including the .py extension).
Importing a Python File
To import a Python file into another program, you'll need to use the import statement,
followed by the name of the file (without the .py extension). For example:
import hello