0% found this document useful (0 votes)
8 views19 pages

Python Basics: Variables and Operators

The document provides an introduction to Python programming, focusing on variables, data types, and operators. It includes practical exercises for declaring variables, performing calculations, and understanding the importance of parentheses in expressions. Additionally, it introduces lists as a way to store multiple values in Python.

Uploaded by

Pratinav Tewari
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)
8 views19 pages

Python Basics: Variables and Operators

The document provides an introduction to Python programming, focusing on variables, data types, and operators. It includes practical exercises for declaring variables, performing calculations, and understanding the importance of parentheses in expressions. Additionally, it introduces lists as a way to store multiple values in Python.

Uploaded by

Pratinav Tewari
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

Python 101

Variable
Review
Review

What will print?


age = '16'
age = '20'
print(age)
Review
Practice
1. What is the datatype of x = 10

2. What is the datatype of x = ‘3.14’

3. What is the datatype of x = 10.6

4. Write a variable to store your age

5. Write a variable to store your name


Input
Printing a variable

You can print a variable like we did previously you can put the variable name inside
the round brackets. print(variable_name) But sometimes you want to print text before
the variable. For example you might want to have have a variable age where we age
the user their age and then we want to print ‘I am’’ age “years old’

age = input(“How old are


you?”)
print(‘I am ‘ + age + ‘years
old’)
Review
Practice
1. Declare two variables num1 and num2.

2. Assign the values 10 and 5 to num1 and num2, respectively.

3. Calculate the sum of num1 and num2 and store the result in a

variable called sum.

4. Display the calculated sum using the print() function.


Practice
1. Declare two variables length and width.

2. In both variables use input() and ask the user what is the length

and what is the width.

3. Create a new variable called area and find the area by

multiplying length and width

4. Display the calculated sum using the print() function.


Operators
Operators in Python are special symbols or characters that
allow you to perform various operations on data, like
numbers and strings. They are like building blocks that help
you manipulate and interact with data in your programs.
Here are some commonly used operators in Python.
There’s
Variables

Print both of these


print(10/3)
print(10//3)
Operators
Operators
Importance of round brackets
If you have a simple math expression: 2 + 3 * 4. Without
parentheses, Python follows some rules, and it will first do
the multiplication (3 * 4 = 12) and then the addition (2 + 12 =
14), giving you the result [Link] if you put parentheses
around (2 + 3) * 4, now, the result becomes 20, because
Python respects the grouping you've set with the
parentheses. Parentheses are also useful for calling
functions or passing arguments. They make sure the right
values go to the right places.
Operators
Lists
lists are like special containers that can hold multiple
values at once. Imagine it as a magical bag where you can
keep different things together.
Lists

You might also like