FALLSEMFRE2024-25 CSE1012 ETH AP2024253000300 2024-10-14 Reference-Material-I
FALLSEMFRE2024-25 CSE1012 ETH AP2024253000300 2024-10-14 Reference-Material-I
Python (CSE1012)
Agenda / Contents
01 Numbers
02 Variables or Identifiers
03
04
05
04-10-2023 1
Data Types
• Variables can hold values of different types called Data Types
04-10-2023 3
Data Types
• Python has various standard data types that are used to
define operations possible on them and the storage method
for each of them
04-10-2023 4
Assigning or Initializing Variables
• In Python, you need not explicitly declare variables to
reserve memory space
• Operand on the left side of (=) is the name and right side is
the value to be stored
04-10-2023 5
Assigning or Initializing Variables
# Assigning Values to Variables
num=7
amt=123.45
code=‘A’
msg=“Hello”
print(“The Number is: ”,num)
print(“The Character is: ”,code)
print(“The Message is: ”,msg)
04-10-2023 6
Re-assigning Values to Variables
• In Python, you can re-assign values to variables as many
times as needed
04-10-2023 7
Re-assigning Values to Variables
#Program to re-assign values to Variables
val=2
print(val)
val=“Hello”
print(val)
val=23.5
print(val)
04-10-2023 8
Multiple assignment
• Python allows you to assign a single value to multiple
variables simultaneously
• Ex.
sum = flag = a = b = 0
04-10-2023 9
Multiple assignment diff data type
• Python also allows assigning multiple variables with different
data types
• Ex.
sum, a, b, msg = 0, 2, 3, “RESULT”
04-10-2023 10
Multiple statement in single line
• Multiple statements in a single line should be separated by a
semicolon
• Ex.
msg=“Hello”; print(msg)
04-10-2023 11
Boolean Data Type
• Boolean is another data type in Python.
• A variable of Boolean type can have one of the two values-
True or False.
• Similar to other variables, the Boolean variables are also
created while we assign a value to them or when we use a
relational operator on them.
04-10-2023 12
User Input
• Python uses input() function to allow user input
• This function takes user input as string
• Ex.
name=input(“What’s your name?”)
age=input(“Enter your age: “)
print(name + “, you are ” + age + ” years old ”)
04-10-2023 13
User Input
04-10-2023 14
Comments
• Comments are the non-executable statements in a program.
They are just added to describe the statements in the
program code. Comments make the program easily
readable and understandable by the programmer as well as
other users who are seeing the code. The interpreter simply
ignores the comments.
04-10-2023 15
Comments
• Comments are the non-executable statements in a program.
04-10-2023 16
Comments
• Comments make the program easily readable and
understandable by the programmer as well as other users
who are seeing the code.
04-10-2023 17
Comments
• In Python, a hash sign (#) that is not inside a string literal
begins a comment.
04-10-2023 18
Indentation
• Whitespace at the beginning of the line is called
indentation.
04-10-2023 19
Indentation
• In a Python program, the leading whitespace including
spaces and tabs at the beginning of the logical line
determines the indentation level of that logical line.
04-10-2023 20
Indentation
04-10-2023 21
Reserved Words
• Reserved or keywords have pre-defined meaning
04-10-2023 22
Reserved Words
04-10-2023 23
Thank You