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

PPT-2 - Copy

This document provides an overview of Python data types, including comments, variables, built-in data types, and various expressions. It explains how to use comments, the structure of variable names, and the characteristics of different data types such as None, numeric types, and strings. Additionally, it covers assignment operations and different types of expressions in Python, including arithmetic, relational, and logical expressions.

Uploaded by

Akshat Joshi
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 views

PPT-2 - Copy

This document provides an overview of Python data types, including comments, variables, built-in data types, and various expressions. It explains how to use comments, the structure of variable names, and the characteristics of different data types such as None, numeric types, and strings. Additionally, it covers assignment operations and different types of expressions in Python, including arithmetic, relational, and logical expressions.

Uploaded by

Akshat Joshi
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/ 37

Python Programming

Prof. Swasti Patel, Assistant Professor


Information Technology
CHAPTER-2
Python Data Types
Comments in Python
➢ Single Line Comments
➢ Comments are non-executable statements.
➢ Python compiler nor PVM will execute them.

#To find the sum of two numbers a = 10 # store 10 into


variable a
Comments in Python
➢ When we want to mark several lines as comment, then we can write the
previous block of code inside ””” (triple double quotes) or ’’’ (triple
single quotes) in the beginning and ending of the block as.

”””
Write a program to find the total marks scored by a
student in the subjects
”””

’’’
Write a program to find the total marks scored by a
student in the subjects
’’’
Comments in Python
➢ Python supports only single line comments.
➢ Multiline comments are not available in Python.
➢ Triple double quotes or triple single quotes are actually not multiline
comments but they are regular strings with the exception that they can
span multiple lines.
➢ Use of ’’’ or ””” are not recommended for comments as they internally
occupy memory.
Variables in Python
➢ In many languages, the concept of variable is
connected to memory location.
➢ In python, a variable is seen as a tag
that is tied to some value.
➢ Variable names in Python can be any length.
➢ It can consist of uppercase and lowercase letters (A-Z,
➢ a-z), digits (0-9), and the underscore character (_).
➢ A restriction is that, a variable name can contain digits, the first
character of a variable name cannot be a digit.
Datatypes in Python
➢ A datatype represents the type of data stored into a variable or
memory.
➢ The datatypes which are already avaiablein Python
language are called Built-in datatypes
➢ The datatypes which are created by the programmers are called User-
Defined datatypes.
Built-in Datatypes
➢ None Type
➢ Numeric Types
➢ Sequences
➢ Sets
➢ Mappings
None Type
➢ ‘None’ datatype represents an object that does not contain
➢ any value.
➢ In Java, it is called ‘Null’ Object’, but in Python it is called ‘None’ object.
➢ In Python program, maximum of only one ‘None’ object is
➢ provided.
➢ ‘None’ type is used inside a function as a default value of the
arguments.
➢ When calling the function, if no value is passed, then the
➢ default value will be taken as ‘None’.
➢ In Boolean expressions, ‘None’ datatype is represents ‘False’
Numeric Type
➢ int
➢ float
➢ complex
Int DataType
➢ The int datatype represents an integer number.
➢ An integer number is a number without any decimal
point or fraction part.
➢ int datatype supports both negative and positive integer numbers.
➢ It can store very large integer numbers conveniently.

a = 10
b = -15
Float DataType
➢ The float datatype represents floating point numbers.
➢ A floating point number is a number that contains a decimal point.

#For example : 0.5, -3.4567, 290.08,0.001


num = 123.45

x = 22.55e3
#here the float value is 22.55 x 103
Bool DataType
➢ The bool datatype in Python represents
➢ boolean values.
➢ There are only two boolean values True or False that can be represented
by this datatype.
➢ Python internally represents True as 1 and
➢ False as 0.
Bool DataType
➢ The bool datatype in Python represents
➢ boolean values.
➢ There are only two boolean values True or False that can be represented
by this datatype.
➢ Python internally represents True as 1 and
➢ False as 0.
Print Statement

>>>print “Python" Python

>>>print “Python Programming" Python Programming

>>> print "Hi, I am Learning Python Programming." Hi, I am Learning Python


Programming.
Print Statement

>>> print 25
25

>>> print 2*2 4

>>> print 2 + 5 + 9
16
Print Statement

>>> print "Hello,","I","am",“Python" Hello, I am Python

>>> print “Python","is",27,"years","old" Python is 27 years old

>>> print 1,2,3,4,5,6,7,8,9,0


1234567890
String DataType
➢ Strings in Python are identified as a contiguous set of characters
represented in the quotation marks. Python allows for either pairs of
single or double quotes. Subsets of strings can be taken using the slice
operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the
string and working their way from -1 at the end.
➢ The plus (+) sign is the string concatenation operator and the asterisk (*)
is the repetition operator. For example −
String Operations
String Operations
String Operations
String Operations
Assignment Operations
➢ Operators are used to perform operations on values and variables.
These are the special symbols that carry out arithmetic, logical, bitwise
computations. The value the operator operates on is known as Operand.
➢ Here, we will cover Assignment Operators in Python. So, Assignment
Operators are used to assigning values to variables.
Assignment Operations
Assignment Operations
Expressions
➢ Constant Expressions
➢ Arithmetic Expressions
➢ Integral Expressions
➢ Floating Expressions
➢ Relational Expressions
➢ Logical Expressions
➢ Bitwise Expressions
➢ Combinational Expressions
Constant Expressions
➢ These are the expressions that have constant values only.
Arithmetic Expressions
➢ An arithmetic expression is a combination
of numeric values, operators, and
sometimes parenthesis. The result of this
type of expression is also a numeric value.
The operators used in these expressions are
arithmetic operators like addition,
subtraction, etc. Here are some arithmetic
operators in Python:
Arithmetic Expressions
Integral Expressions
➢ These are the kind of expressions that
produce only integer results after all
computations and type conversions.
Floating Expressions
➢ These are the kind of expressions that produce only These are the kind of
expressions which produce floating point numbers as result after all
computations and type conversions. integer results after all computations and
type conversions.
Relational Expressions
➢ In these types of expressions, arithmetic expressions are written on both sides
of relational operator (> , < , >= , <=). Those arithmetic expressions are
evaluated first, and then compared as per relational operator and produce a
boolean output in the end. These expressions are also called Boolean
expressions.
Logical Expressions
➢ These are kinds of expressions that result in either True or False. It basically
specifies one or more conditions. For example, (10 == 9) is a condition if 10 is
equal to 9. As we know it is not correct, so it will return False. Studying logical
expressions, we also come across some logical operators which can be seen in
logical expressions most often. Here are some logical operators in Python:
Logical Expressions
Bitwise Expressions
➢ These are the kind of expressions in which computations are performed at bit
level.
Combinational Expressions
➢ We can also use different types of expressions in a single expression, and that
will be termed as combinational expressions.
www.paruluniversity.ac.in

You might also like