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

Day2_Python Data-Type

This document is a presentation on Python data types, covering various topics including literals, built-in functions, escape sequences, comments, variables, identifiers, built-in data types, indentation, reserved keywords, and operators. It provides examples and explanations for each concept to aid understanding. The presentation is authored by Vinay Kant and was last updated on July 13, 2021.

Uploaded by

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

Day2_Python Data-Type

This document is a presentation on Python data types, covering various topics including literals, built-in functions, escape sequences, comments, variables, identifiers, built-in data types, indentation, reserved keywords, and operators. It provides examples and explanations for each concept to aid understanding. The presentation is authored by Vinay Kant and was last updated on July 13, 2021.

Uploaded by

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

TOPIC: Python Data-Type

COURSE: Python Programming

PPT SL.NO.: 1 of 19

VERSION: 01 LAST UPDATED ON: 13/07/2021

NIEL Presentation By: Vinay Kant


Content
◻ Literals in Python
◻ Build-in format() Function
◻ Escape Sequences
◻ String Formatting Function
◻ Comments and Constants in Python
◻ Variables in Python
◻ Identifier in Python
◻ Built-in Data Types
◻ Python Indentation
◻ Reserved Keywords in Python
◻ Operators in Python
Literals in Python
❑ Literal: Literal is a raw data given in a variable or
constant. In Python, there are various types of
literals they are as follows:

Numeric Literals:

Numeric Literals are immutable (unchangeable).


Numeric literals can belong to 4 different numerical
types Integer, long integers, Float, and Complex.
Examples : 10, 535353535353L, 10.5, (50+5j)
String literals
A string literal is a sequence of characters surrounded by quotes. We can use both
single, double quotes for a string. And, a character literal is a single character
surrounded by single or double quotes.
Example : >>> print(‘Hello’) # Using Single quotes
Hello

Example : >>> print(“Hello”) # Using Double quotes


Hello

◻Using Triple quotes : we can specify multi-line strings using triple quotes.
◻Example

‘ ‘ ‘ good morning everyone.


Welcome to python
Programming language. ‘ ‘ ‘
Build-in format() Function
◻ Any floating-point value may contain an arbitrary number of
decimal places, so it is always recommended to use the build-in
format() function to produce string version of a number with
specific number of decimal places.

◻ For Example:

◻ Without using build-in format() function


print(float(16/(float(3))))
5.33333333333333

◻ Using build-in format() function


print(format(float(16/(float(3))), '.2f'))
5.33
Escape Sequences
◻Some characters cannot be directly included in a
string. Such characters must be escaped by placing
a backslash before them.
Example: print('what's your name?')
SyntaxError: invalid syntax Escape Seq. Purpose
\’ ‘
\” “
Example: print('what\'s your name?') \n new line
\t tab
what's your name?
Example:
print("boy replies,\"my name is Vijay\"")
boy replies,"my name is Vijay"
String Formatting Function
◻ This function can be used to control the display of
strings.
Syntax: format(value, format_specifier)
◻ Value -> value or string to be displayed
◻ format_specifier -> formatting options

Example:
format('Hello', '<30')
'Hello '

Example:
format('Hello', '>30')
' Hello'
Comments and Constants in Python
❑ Creating a Comment
Comments starts with a #, and python will ignore them:
Example :
# this is a comment
print(“Hello”)

“ “ “this is a very long sentence


and it after two lines” ” ”

❑ Constant : A constant is a type of variable whose value cannot be


changed. It is helpful to think of constants as containers that hold
information which cannot be changed later.
Variables in Python
◻ Named labels, whose values can be used and processed
during program run, are called Variables.
◻ By assigning different data types to variables, you can
store integers, floating point or characters in these
variables.
◻ Examples :
a = 70
b = 100.0
name = “john”
Identifier in Python
Identifier is the name given to a variable, function, class
or object. All identifiers must obey the following rules.
An identifier:
1. Is a sequence of characters that consists of letter, digit
and underscore.
2. Can be of any length
3. Start with letter which can be lower case
4. Can start with underscore ‘_’
5. Can not start with a digit
6. Can not be a keyword
Example : _sum, person
Built-in Data Types
◻ Python has the following data types built-in by
default.
◻ Text Type : str
◻ Numeric Types : int, float, complex
◻ Sequence Types : list, tuple, range
◻ Mapping Type : dict
◻ Set Types : set, frozenset
◻ Boolean Type : bool
◻ Binary Types : bytes, bytearray, memoryview
Python Indentation
◻ Indentation refers to the spaces at the beginning of a code
line.
◻ Whereas in other programming languages the indentation in
code is for readability only, but the indentation in Python is
very important.
◻ Python uses indentation to indicate a block of code.

Example:
if 5 > 2:
print("Five is greater than two!")

Note: Python will give you an error if you skip the indentation.
Reserved Keywords in Python

◻ Keywords are reserved words with fixed meanings


assigned to them. Keywords can not be used as an
identifier or variable.

◻ Some of the examples of keywords in python are :-


and, or, not, if, else, elif, for, while, return etc.
Operators in Python
Types of Operators used in Python
◻ Arithmetic Operators (+, -, *, /, %, **, //)
◻ Comparison Operators (==, >, <, >=, <=)
❑ Assignment Operators (=, +=, -=, *=, /=)
◻ Logical Operators (AND, OR NOT)
◻ Bitwise Operators (&, |, ^, >>, <<, ~)
◻ Membership Operators (in, not in)
◻ Identity Operators (is, is not)
Arithmetic Operators
❑It is used for performing basic Arithmetic
Operation (+, -, *, /, %, **, //).
Example :
>>> a, b, c = 10, 5, 2
>>> print(“sum =”,(a+b))
sum = 15
Comparison Operators
◻ These operators (==, >, <, >=, <=) compare the
values on either sides of them and decide the
relation among them.
◻ Example :
>>> a, b = 10, 5
>>> print(“a>b is”,(a>b))
a>b is True
Assignment Operators
◻ Python provide various assignment operators
(=, +=, -=, *=, /=).
◻ Example :
>>> a, b = 10, 5
>>> a+=b
>>>Print(a)
15
Logical Operators
◻ There are three operators – and, or, not
◻ Example :
>>> a, b, c, d = 10,5,2,1
>>> print((a>b) and(c>d))
True
Thank you!
If you have any query, please contact:

Vinay Kant
Contact no: +91-8393903778
email: [email protected]

NIEL www.nielit.gov.in/haridwar

You might also like