0% found this document useful (0 votes)
6 views

python3

The document provides an introduction to programming concepts using Python, including variable creation, assignment, and printing values. It explains the importance of order of instructions and spacing in code execution, along with examples of variable assignment and expressions. Additionally, it covers the BODMAS rule for evaluating expressions and demonstrates its application with Python code snippets.

Uploaded by

Prachi More
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

python3

The document provides an introduction to programming concepts using Python, including variable creation, assignment, and printing values. It explains the importance of order of instructions and spacing in code execution, along with examples of variable assignment and expressions. Additionally, it covers the BODMAS rule for evaluating expressions and demonstrates its application with Python code snippets.

Uploaded by

Prachi More
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

7/27/24, 8:53 PM Revolutionizing the Job Market | NxtWave

Sequence of Instructions
Program
A program is a sequence of instructions given to a computer.

Defining a Variable

A variable gets created when you assign a value to it for the first time.

Code
PYTHON

1 age = 10

Printing Value in a Variable

Code
PYTHON

1 age = 10
2 print(age)

Output

10

Code
PYTHON

1 age = 10
2 print("age")

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=6bdf14a9-2664-4a96-9764-89d965de71a0&s_id=3a42963… 1/5
7/27/24, 8:53 PM Revolutionizing the Job Market | NxtWave

Output

age

Variable name enclosed in quotes will print variable rather than the value in it.
If you intend to print value, do not enclose the variable in quotes.

Order of Instructions

Python executes the code line-by-line.

Code
PYTHON

1 print(age)
2 age = 10

Output

NameError: name 'age' is not defined

Variable

age is not created by the time we tried to print.

Spacing in Python

Having spaces at the beginning of line causes errors.

Code
PYTHON

1 a = 10 * 5
2 b = 5 * 0.5
https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=6bdf14a9-2664-4a96-9764-89d965de71a0&s_id=3a42963… 2/5
7/27/24, 8:53 PM Revolutionizing the Job Market | NxtWave

3 b = a + b

Output

File "main.py", line 3


b = a + b
^
IndentationError: unexpected indent

Variable Assignment

Values in the variables can be changed.

Code
PYTHON

1 a = 1
2 print(a)
3 a = 2
4 print(a)

Output

1
2

Examples of Variable Assignment

Code

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=6bdf14a9-2664-4a96-9764-89d965de71a0&s_id=3a42963… 3/5
7/27/24, 8:53 PM Revolutionizing the Job Market | NxtWave

PYTHON

1 a = 2
2 print(a)
3 a = a + 1
4 print(a)

Output

2
3

Code
PYTHON

1 a = 1
2 b = 2
3 a = b + 1
4 print(a)
5 print(b)

Output

3
2

Expression

An expression is a valid combination of values, variables and operators.

Examples
a*b
a+2
5*2+3*4

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=6bdf14a9-2664-4a96-9764-89d965de71a0&s_id=3a42963… 4/5
7/27/24, 8:53 PM Revolutionizing the Job Market | NxtWave

BODMAS
The standard order of evaluating an expression

Brackets (B)

Orders (O)

Division (D)

Multiplication (M)

Addition (A)

Subtraction (S)

Step by Step Explanation

(5 * 2) + (3 * 4)
(10) + (12)
22

Code
PYTHON

1 print(10 / 2 + 3)
2 print(10 / (2 + 3))

Output

8.0
2.0

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=6bdf14a9-2664-4a96-9764-89d965de71a0&s_id=3a42963… 5/5

You might also like