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

FALLSEMFRE2024-25 CSE1012 ETH AP2024253000300 2024-10-14 Reference-Material-I

Uploaded by

shafeeqasstudent
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 views24 pages

FALLSEMFRE2024-25 CSE1012 ETH AP2024253000300 2024-10-14 Reference-Material-I

Uploaded by

shafeeqasstudent
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
You are on page 1/ 24

Problem Solving Using

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

• Different data types needed to store different types of values


in the variables

• Ex. A person’s age is stored in number, Name in characters,


address is a mixture of numbers and characters

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

• We can even create our own data types in Python (like


classes)

04-10-2023 4
Assigning or Initializing Variables
• In Python, you need not explicitly declare variables to
reserve memory space

• Declaration is done automatically when a value is assigned to


the variable using equal sign (=)

• 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

• You may change data types of the same variable in


subsequent statement

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.

• They are just added to describe the statements in the


program code.

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.

• The interpreter simply ignores the comments.

04-10-2023 17
Comments
• In Python, a hash sign (#) that is not inside a string literal
begins a comment.

• All characters following the # and up to the end of the line


are part of the comment

04-10-2023 18
Indentation
• Whitespace at the beginning of the line is called
indentation.

• These whitespaces or the indentation are very important in


Python.

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

• They are not available for naming variables/Identifiers

04-10-2023 22
Reserved Words

04-10-2023 23
Thank You

You might also like