Revision Of Python Basics - Working With Python Files

 


In this post we are going to learn Working with Python Files. Let's us start by creating a new file in Python IDLE and create a simple program.

Perform the below mentioned steps to start Python programming language.

Step 1: Click on Start button  -> Search Python 3.9.

Step 2: Click on the IDLE (Python 3.9 32 - Bit). The Python Shell window will open.

Step 3: Click on the File menu and then click on the New file option to create a new file in Python

A new Python window will open. Type the following program code in the Python window.

#Program to divide two numbers
x = 50
y = 30
z = x/y
print (z)

Let us discuss the above mentioned code.

#Program to divide two numbers: First line of the code is a comment. There are two types of comments in Python, i.e., Single Line comment (starts with a hash # sign), and Multiline comment (given inside the """ """ triple quotes).

x = 50 and y = 30: These are variable declaration statements. x and y are variables containing values 50 and 30 respectively. The (=) equals to operators is used to assign values to variables.

 z = x/y: In this expression,  x, y and z are variables. The = equals to is an assignment operator, and/ is division sign of arithmetic operators. +, -, /, * and % are different arithmetic operators available in Python. x/y is an arithmetic expression.

print (z): This is an output statement that prints the result of the arithmetic expression.

Running the Python program

After typing the code, perform the below mentioned steps to run a Python program.

Click on the Run menu and then click on the Run Module option or Press the F5 key to run the program.

The program will run and the output is displayed in the Python Shell window.

Saving a Program/File

After creating a program, perform the below mentioned steps to save a file or program in Python

Step 1: Click on the File menu and then click on the Save option. The Save As dialog box will appear.

Step 2: Type the file name with the extension .py such as codewithanmol.py. The file will be saved. 

Fact - Python files are saved the extension .py.

We will study Tokens, Integer, Variables, etc. In another post. Stay Safe, Keep Learning And Keep Growing.


 

Post a Comment

Previous Post Next Post