0% found this document useful (0 votes)
5 views5 pages

Python Programming Basics Explained

The document provides an introduction to Python programming, detailing its history, advantages, applications, and basic concepts such as comments, identifiers, variables, data types, and operators. It explains how to run Python code in both interactive and script modes, along with examples of using the print() and input() functions. Additionally, it outlines the rules for defining variables and the basic data types available in Python.

Uploaded by

NIDHI WAYKOLE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Python Programming Basics Explained

The document provides an introduction to Python programming, detailing its history, advantages, applications, and basic concepts such as comments, identifiers, variables, data types, and operators. It explains how to run Python code in both interactive and script modes, along with examples of using the print() and input() functions. Additionally, it outlines the rules for defining variables and the basic data types available in Python.

Uploaded by

NIDHI WAYKOLE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Python programming

It was initially designed by Guido van Rossum in 1991 and


developed by Python Software Foundation. It was mainly developed
for emphasis on code readability, and its syntax allows
programmers to express concepts in fewer lines of code.

Advantages of Python
[Link] to Learn and Use
[Link] and Open-Source
[Link] Development
[Link] Language
[Link] Range of Libraries and Frameworks
[Link] Typed
[Link]
[Link] Community Support

Applications of Python
[Link] using Python
[Link] Analysis using Python
[Link] Learning
[Link] Applications
[Link] development

Comments:
Comments are used to write something which the programmer does
not want to execute.
Types of comments:
There are two types of comments in python:
Single line comment:Written using #
Multiline comment: Written using ‘ ‘ ‘ Comment ‘ ‘ ‘
Identifiers
A Python identifier is a name used to identify a variable, function,
class, module or other object.
Keywords:Reserve word of the compiler/interpreter which can’t be
used as an identifier.
For example: if,for,while,elif,print,else
Variables and Datatypes:
A variable is a name given to a memory location in a program for
execution.
For example :a=30
name=”DPS”
Y=73.4
Data Types:
Following are the basic data types in python.
[Link]
[Link]
[Link]
[Link]
Rules for defining variables in python
[Link] names must start with a letter (a-z, A-Z) or an
underscore (_)
2.A variable name cannot start with a number.
3. A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
4. Variable names are case-sensitive (age, Age and AGE are three
different variables)
5.A variable name cannot be any of the Python keywords.
Examples:a,b,harry,five,_five,dps2015

Operators in Python
[Link] Operators: +,-,*,/
[Link] Operators: =,+=,-=,*=
[Link] operators: ==,>,<,>=,<=
[Link] Operators: and ,or,not

In the Python programming language, there are two ways in which


we can run our code:
1. Interactive mode
2. Script mode
● In the interactive mode as we enter a command and press
enter, the very next step we get the output.
● Script mode is very suitable for writing long pieces of code. It is
much preferred over interactive mode by experts in the program.
The file made in the script mode is by default saved in the Python
installation folder and the extension to save a python file is “.py”.

How to run python code in script mode?

In order to run a code in script mode follow the following steps.

Step 2: After writing the code, save the file using the “.py”
extension.
Step 3: Now select the Run module from Run Menu or press F5.
Step 5: You will see the output on your command prompt.
print () function:
Python print() function prints the message to the screen or any
other standard output device.
The message can be a string, or any other object, the object will be
converted into a string before written to the screen. input()
function:
This function allows the user to take input from the keyboard as a
string.
Example:
1.#Program to display String
name=input(“Enter your name”)
print(“Hello “,name)
>>>DPS
Output: Hello,DPS

2.#program to accept integer values


n1=int(input(“Enter first number”))
n2=int(input(“Enter second number”))
print(“Addition is”,n1+n2)
print(“Subtraction is “,n1-n2)
print(“Multiplication is”,n1*n2)
print(“Division is “,n1/n2)

#Program to calculate area and perimeter of square

side=int(input(“Enter the side of the square”))


area=side*side
p=4*side
print(“Area of square is :”,area)
print(“Perimeter of square is”,p)
#Program to calculate area and perimeter of rectangle
L=int(input(“Enter length”))
B=int(input(“Enter breadth”))
area=L*B
p=2*(L+B)
print(“Area of rectangle is”,area)
print(“Perimeter of rectangle is “,p)

Output:

You might also like