SlideShare a Scribd company logo
Identifiers :
An identifier is a name given to a variable,function,class.
Eg: a = 20
It is a valid Python statement.
Here 'a' is an identifier.
Rules to define identifiers in Python:
1. The only allowed characters in Python are
Alphabet symbols(either lower case or upper case)
Digits(0 to 9)
Underscore symbol(_).
Ex: total_1234 = 22 # Valid
2. An Identifier can be begin with an alphabet and underscoret(A-Z and a-z
and_)
Ex: _abc_abc_ = 22 # Valid
3. Identifier cannot starts with digit but is allowed everywhere else.
Ex: plus1=10 #valid
1plus=10 # In valid
SyntaxError: invalid syntax
3.One cannot use spaces and special symbols like ! @ # $ % etc….
as identifiers.
Ex: cash$ = 10 # '$'is a special character invalid identifier
SyntaxError: invalid syntax
4. Identifiers are case sensitive. Of course Python language itself is case
sensitive language.
Ex: total=10
TOTAL=999
print(total) o/p : 10
print(TOTAL) o/p : 999
4.Keywords cannot be used as identifiers.
Ex: x = 10 # Valid
if = 33 # In valid if is a keyword in Python
SyntaxError: invalid syntax
5. Identifiers can be of any length.
Ex : Abcedwrtyyhfdg123_=10
Q. Which of the following are valid Python identifiers?
123total = 22
total1234 = 22
java2share = 'Java‘
ca$h = 33
_abc_abc_ = 22
def = 44
for = 3
_p = 33
Keywords:
1. In Python some words are reserved to represent some
meaning or functionality. Such type of words are called
Reserved words or keywords.
2. There are 33 reserved words available in Python.
List of keywords in python:
and as not
assert finally or
break for pass
class from nonlocal
continue global raise
def if return
del import try
elif in while
else is with
except lambda yield
False True None
2. All 33 keywords contains only alphabets symbols.
3. Except the following 3 reserved words, all contain only
lowercase alphabet symbols.
True
False
None
4. True and False are Boolean values , For Boolean values,
compulsory you need to use capital letter 'T' in True and
capital letter 'F' in False.
Ex: a = True # Valid
A=true # In valid
NameError: name 'true' is not defined
Statements and Expressions:
A statement is an instruction or statement is a unit of code that can be executed by
python interpreter.
Eg: z = 1 // this iExamples: Y=x + 17 >>> x=10 >>> z=x+20 >>> z 30 s an assignment
statement
Expression:
An expression is a combination of values, variables, and operators which are evaluated
to make a new value b.
>>> 20 # A single value
>>> z # A single variable
>>> z=10 # A statement
But expression is a combination of variable, operator and value which is evaluated by
using assignment operator in script mode.
Examples: Y=x + 17
>>> x=10 >>> z=x+20 >>> z o/p : 30
When the expression is used in interactive mode, is evaluated by the interpreter and
the result is displayed instantly.
Eg:
>>> 8+2
10
Variables:
Variables are nothing but reserved memory locations to store
values. That means when you create a variable some space is
reserved in memory.
• One of the most powerful features of a programming language
is the ability to manipulate variables.
• A variable is a name that refers to a value. An assignment
statement creates new variables and gives them values:
• The general format for assigning values is as follows.
• Variable name = expression
• The equal sign (=) also known as simple assignment operator
is used to assign values to variables.
• In general format, the operand to the left of the = operator is
the name of the variable and operator to the right of the =
operator is the expression which can be a value.
Eg:1. >>>name=‘python’
>>> number=100
>>> miles=1000.0
>>> name
Python
>>> number
100
>>> miles
1000
• This example makes three assignment statements.
• Integer type assigned to a variable number, float type assigned
to a variable miles ,string type value is assigned to a variable
name and print the value assigned to these variables.
2. In python not only the value of variable may change during program
execution but also the type of data that is assigned.
In Python, We don't need to specify the type of variable because
Python is a loosely typed language.
>>>Century=100
>>> Century = “hundred”
>>> Century
‘hundred’
3. Python allows you to assign value to several variables
simultaneously.
1. >>> a=b=c=1 4.Assign multiple values to multiple variables
2.>>> a
1 a,b,c=5,50, 15
3.>>> b >>> a 5
1 >>>b 50
4.>>> c >>>c 15
1
Operators in Python
• The operator can be defined as a symbol which is responsible
for a particular operation between two operands.
• Python provides a variety of operators described as follows.
• Arithmetic operators :
• + (addition) eg: a=20; b=10 then a + b=30
• - (subtraction) eg: a=20; b=10 then a - b=10
• *(multiplication) eg: a=20; b=10 then a * b=200
• / (divide) eg: a=20; b=10 then a / b=2
• %( reminder) eg: a=20; b=10 then a % b=0
• // (floor division) eg: a=24; b=7 then a // b=3
• ** (exponent) eg: a=2; b=3 then a ** b=8
Operators in Python
• Assignment operators :
• = (Assigns to)
• += (Assignment after Addition)
• -= (Assignment after Subtraction)
• *= (Assignment after Multiplication)
• /= (Assignment after Division)
• %= (Assignment after Modulus)
• **= (Assignment after Exponent)
• //= (Assignment after floor division)
• Comparison operators :
• == (Equal to)
• != (Not equal to)
• <= (Less than or equal)
• >= (Greater than or equal)
• < (Less than)
• > (Greater than)
• Logical operators :
• and (logical and)
• or (logical or)
• not (logical not)
• Bitwise operators :
• & (binary and)
• | (binary or)
• ^ (binary xor)
• ~ (negation)
• << (left shift)
• >> (right shift)
• Membership operators :
• in (True, If the value is present in the data structure)
• not in (True, If the value is not present in the data structure)
• Identity operators :
• is (Returns true if both variables are the same object)
• is not (Returns true if both variables are not the same object)
Precedence and Associativity
Comments in Python
• In general, Comments are used in a programming language
to describe the program or to hide the some part of code
from the interpreter.
• Comments in Python can be used to explain any program
code. It can also be used to hide the code as well.
• Comment is not a part of the program, but it enhances the
interactivity of the program and makes the program
readable.
Python supports two types of comments:
• Single Line Comment
• Multi Line Comment
Comments in Python
• Single Line Comment:
In case user wants to specify a single line comment, then comment must start
with ‘#’
Example:
# This is single line comment
print "Hello Python"
Output:
Hello Python
• Multi Line Comment:
Multi lined comment can be given inside triple quotes.
Example:
'''This is
Multiline
Comment'''
print "Hello Python"
Output:
Hello Python
• Data types:
• Data types specify the type of data like numbers and characters to be stored
and manipulated with in a program. Basic data type of python are
• Numbers
• Boolean
• Strings
• None
Numbers:
• Integers, floating point numbers and complex numbers fall under python
numbers category. They are defined as int, float and complex class in
python.
1. integer:
• Int, or integer, is a whole number, positive or negative, without decimals,
of unlimited length, it is only limited by the memory available.
Example:
a=10
b=-12
c=123456789
2. float:
• Float or "floating point number" is a number, positive or negative, containing
one or more decimals.
Example:
• X=1.0
• Y=12.3
• Z= -13.4
3. complex:
• Complex numbers are written in the form , “x+yj" where x is the real part and
y is the imaginary part.
Example:
A=2+5j
B=-3+4j
C=-6j
Boolean:
Booleans are essential when you start using conditional statements.
Python Boolean type is one of the built-in data types provided by Python,
which represents one of the two values i.e. True or False. The boolean
values, True and False treated as reserved words.
String:
• The string can be defined as the sequence of characters
represented in the quotation marks. In python, we can use single,
double, or triple quotes to define a string.
• In the case of string handling, the operator + is used to concatenate
two strings as the operation "hello"+" python" returns "hello
python".
Example:
EX : S1=‘Welcome’ #using single quotes
S1 Output: ‘Welcome’
print(S1) Output: Welcome
Ex: S2=“To” #using double quotes
S2 Output: 'to'
print(S2) Output: to
Ex: S3=‘’’Python’’’ #using triple quotes
S3 Output: "'python'"
print(S3) Output: 'python‘
Ex: Name1= ‘Hello’
Name2=‘python’
Name1 + Name2 Output: ‘Hellopython’
print(Name1 + Name2) Output: Hellopython
Example:
a=10
b=“Python"
c = 10.5
d=2.14j
e=True
print("Data type of Variable a :",type(a))
print("Data type of Variable b :",type(b))
print("Data type of Variable c :",type(c))
print("Data type of Variable d :",type(d))
print(“Data type of Variable e :”,type(e))
Output:
• Data type of Variable a : <class 'int'>
• Data type of Variable b : <class 'str'>
• Data type of Variable c : <class 'float'>
• Data type of Variable d : <class 'complex'>
• Data type of Variable e : <class 'bool'>
Indentation:
• In Python it is a requirement and not a matter of style to indent the
program. This makes the code cleaner and easier to understand and
read.
• If a code block has to be deeply nested, then the nested statements
need to be indented further to the right.
• Block 2 and Block 3 are nested under Block 1. 4 white spaces are
used for indentation and are preferred over tabs.
• Incorrect indentation will result in IndentationError.
Block 1
Block 2
Block 3
Block 2, Continuation
Block 1, Continuation
• Reading Input :
• Input() function is used to gather data from the user.
• Syntax : variable_name = input([prompt])
• Where prompt is a string written inside parenthesis.
• The prompt gives an indication to the user of the value that needs
to be entered through the keyboard.
• When user presses Enter key, the program resumes and input
function returns what the user typed as a string.
• Even if the user inputs a number, it is treated as a string and the
variable_name is assigned the value of string.
1. >>> person = input(“what is your name?”)
2. What is your name? John
3. >>>person
4. ‘John’
Print Output
• Print() function allows a program to display text onto the console.
• Print function prints everything as strings.
>>>print(“Hello World”)
Hello World
There are two major string formats which are used inside the print() function to display
the contents on to the console.
1. str.format()
2. f-strings
str.format() method:
• The format() method returns a new string with inserted values.
• syntax: str.format(p0,p1,p2…..k0=v0, k1=v1,…)
• Where p0,p1 are called as positional arguments and k0,k1 are keyword arguments
with their assigned values of v0,v1..
• Positional arguments are a list of arguments that can be accessed with an index of
argument inside curly braces like {index}. Index value starts from zero.
• Keyword arguments are a list of arguments of type keyword = value, that can be
accessed with the name of the argument inside curly braces like {keyword}.
Eg: country = input(“which country do you live in”)
print(“I live in {0}”.format(country))
• Print Output
Eg:
a = 10
b = 20
Print(“the values of a is {0} and b is {1}”.format(a,b))
Print(“the values of b is {1} and a is {0}”.format(a,b))
f-strings:
A f-string is a string literal that is prefixed with “f”. These strings
may contain replacement fields ,and are enclosed within
curly braces { }.
Eg: country = input(“which country do you live in”)
Print(f”I live in {country}”)
Type Conversion in Python:
• Python provides Explicit type conversion functions to directly convert
one data type to another. It is also called as Type Casting in Python
• Python supports following functions
1. int () : This function convert a float number or a string to an integer.
• Eg: float_to_int = int(3.5)
string_to_int = int(“1”) // number is treated as string
print(float_to_int) o/p: 3
print(string_to_int) o/p: 1 will be displayed.
2. float( ) :
• This function convert integer or a string to floating point number using the
float() function.
• Eg: int_to_float = float(8)
string_to_float = float(“1”) // number is treated as string
print(int_to_float)
print(string_to_float)
8.0
1.0 get displayed
• The str() Function : The str() function returns a string which is fairly human
readable.
Eg: int_to_string =str(8)
float_to_string = str(3.5)
Print(int_to_string) prints ‘8’
Print(float_to_string) prints ‘3.5’
• The chr() Function : This function converts an integer to a string of one
character whose ASCII is the same integer used in chr() function. The
integer value should be in the range of 0-255.
Eg: ascii_to_char = chr(100)
Print(“equivalent character for ASCII value of 100 is {ascii_to_char}”)
Output: equivalent character for ASCII value of 100 is d
An integer value corresponding to an ASCII code is converted to character
and printed.
(ASCII A-Z =65 to 90 ; a-z = 97 to 122; 0-9 = 48 to 57)
• The Complex() Function:
• complex() function is used to print a complex number with a real part and
imag*j part.
• If the first argument for the function is a string, it is interpreted as complex
number and the function is called without 2nd parameter.
• If imag is omitted, it defaults to zero
• Eg: complex_with_string = complex(“1”)
– complex_with_number = complex(5,8)
Print(f“result after using string in real part{complex_with_string}”)
– Print(f”result after using numbers in real and imaginary
part{complex_with_number}”)
– Output: result after using string in real part (1+0j)
– result after using numbers in real and imaginary part (5+8j)
The ord() function:
• The ord() function returns an integer representing Unicode
code point for the given Unicode character.
• Eg: 1. unicode_for_integer = ord('4')
print(f“ Unicode code point for integer value of 4 is
{unicode_for_integer}")
Output: Unicode code point for integer value of 4 is 52.
The hex() function:
• Convert an integer number (of any size) to a lowercase
hexadecimal string prefixed with “0x” using hex() function.
• 1. int_to_hex = hex(255)
• 2. print(int_to_hex )
• Output: 0xff
The oct() function:
• Convert an integer number (of any size) to an octal string prefixed with “0o” using
oct() function.
Eg: int_to_oct = oct(255)
print(int_to_oct)
Output: 0o377.
Dynamic and strongly typed language:
• Python is a dynamic language as the type of the variable is determined during run-
time by the interpreter.
• Python is also a strongly typed language as the interpreter keeps track of all the
variables types
• In a strongly typed language, you are simply not allowed to do anything that’s
incompatible with the type of data you are working with.
• For example, Parts of Python Programming Language
>>> 5 + 10
15
>>> 1 + "a“
Traceback (most recent call last):
• when you try to add 1, which is an integer type with "a" which is string type, then
it results in Traceback as they are not compatible.
• In Python, Traceback is printed when an error occurs.
The type() function and is operator:
The syntax for type() function is,
type(object)
The type() function returns the data type of the given object.
1. >>> type(1)
<class ‘int’>
2. >>> type(6.4)
<class ‘float’>
3. >>> type("A")
<class ‘str’>
4. >>> type(True)
<class ‘bool’>
The type() function comes in handy if you forget the type of
variable or an object during the course of writing programs.

More Related Content

Similar to parts_of_python_programming_language.pptx

Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
malekaanjum1
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
Mr. Vikram Singh Slathia
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
Eric Chou
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
Python PPT2
Python PPT2Python PPT2
Python PPT2
Selvakanmani S
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
Ravikiran708913
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
ssuser7f90ae
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
Yusuf Ayuba
 
Python.pdf
Python.pdfPython.pdf
Python.pdf
Shivakumar B N
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
ManishJha237
 
CS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdfCS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdf
Ida Lumintu
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
z9819898203
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
YashwanthMalviya
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
KrishanPalSingh39
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
Aahwini Esware gowda
 

Similar to parts_of_python_programming_language.pptx (20)

Unit - 2 CAP.pptx
Unit - 2 CAP.pptxUnit - 2 CAP.pptx
Unit - 2 CAP.pptx
 
Python revision tour i
Python revision tour iPython revision tour i
Python revision tour i
 
Chapter 2: Elementary Programming
Chapter 2: Elementary ProgrammingChapter 2: Elementary Programming
Chapter 2: Elementary Programming
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Python PPT2
Python PPT2Python PPT2
Python PPT2
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
 
Python slide.1
Python slide.1Python slide.1
Python slide.1
 
Python.pdf
Python.pdfPython.pdf
Python.pdf
 
Basics of Python Programming
Basics of Python ProgrammingBasics of Python Programming
Basics of Python Programming
 
CS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdfCS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdf
 
Chapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programmingChapter-2 is for tokens in C programming
Chapter-2 is for tokens in C programming
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
presentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptxpresentation_data_types_and_operators_1513499834_241350.pptx
presentation_data_types_and_operators_1513499834_241350.pptx
 
2nd PUC Computer science chapter 5 review of c++
2nd PUC Computer science chapter 5   review of c++2nd PUC Computer science chapter 5   review of c++
2nd PUC Computer science chapter 5 review of c++
 
Pointers
PointersPointers
Pointers
 

More from Koteswari Kasireddy

DA Syllabus outline (2).pptx
DA Syllabus outline (2).pptxDA Syllabus outline (2).pptx
DA Syllabus outline (2).pptx
Koteswari Kasireddy
 
Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdf
Koteswari Kasireddy
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
Koteswari Kasireddy
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
Koteswari Kasireddy
 
DBMS_UNIT_1.pdf
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
Koteswari Kasireddy
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
Koteswari Kasireddy
 
WEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
Koteswari Kasireddy
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Koteswari Kasireddy
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
Koteswari Kasireddy
 
Evolution Of WEB_students.pptx
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
Koteswari Kasireddy
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptx
Koteswari Kasireddy
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
Koteswari Kasireddy
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
Koteswari Kasireddy
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
Koteswari Kasireddy
 
algorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
Koteswari Kasireddy
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
Koteswari Kasireddy
 

More from Koteswari Kasireddy (20)

DA Syllabus outline (2).pptx
DA Syllabus outline (2).pptxDA Syllabus outline (2).pptx
DA Syllabus outline (2).pptx
 
Chapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdfChapter-7-Sampling & sampling Distributions.pdf
Chapter-7-Sampling & sampling Distributions.pdf
 
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
 
unit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
 
DBMS_UNIT_1.pdf
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
 
business analytics
business analyticsbusiness analytics
business analytics
 
Relational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptxRelational Model and Relational Algebra.pptx
Relational Model and Relational Algebra.pptx
 
CHAPTER -12 it.pptx
CHAPTER -12 it.pptxCHAPTER -12 it.pptx
CHAPTER -12 it.pptx
 
WEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
 
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptxUnit 4 chapter - 8 Transaction processing Concepts (1).pptx
Unit 4 chapter - 8 Transaction processing Concepts (1).pptx
 
Database System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptxDatabase System Concepts AND architecture [Autosaved].pptx
Database System Concepts AND architecture [Autosaved].pptx
 
Evolution Of WEB_students.pptx
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Control_Statements_in_Python.pptx
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptx
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 
matrices_and_loops.pptx
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
 
algorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 

parts_of_python_programming_language.pptx

  • 1. Identifiers : An identifier is a name given to a variable,function,class. Eg: a = 20 It is a valid Python statement. Here 'a' is an identifier. Rules to define identifiers in Python: 1. The only allowed characters in Python are Alphabet symbols(either lower case or upper case) Digits(0 to 9) Underscore symbol(_). Ex: total_1234 = 22 # Valid
  • 2. 2. An Identifier can be begin with an alphabet and underscoret(A-Z and a-z and_) Ex: _abc_abc_ = 22 # Valid 3. Identifier cannot starts with digit but is allowed everywhere else. Ex: plus1=10 #valid 1plus=10 # In valid SyntaxError: invalid syntax 3.One cannot use spaces and special symbols like ! @ # $ % etc…. as identifiers. Ex: cash$ = 10 # '$'is a special character invalid identifier SyntaxError: invalid syntax 4. Identifiers are case sensitive. Of course Python language itself is case sensitive language. Ex: total=10 TOTAL=999 print(total) o/p : 10 print(TOTAL) o/p : 999
  • 3. 4.Keywords cannot be used as identifiers. Ex: x = 10 # Valid if = 33 # In valid if is a keyword in Python SyntaxError: invalid syntax 5. Identifiers can be of any length. Ex : Abcedwrtyyhfdg123_=10 Q. Which of the following are valid Python identifiers? 123total = 22 total1234 = 22 java2share = 'Java‘ ca$h = 33 _abc_abc_ = 22 def = 44 for = 3 _p = 33
  • 4. Keywords: 1. In Python some words are reserved to represent some meaning or functionality. Such type of words are called Reserved words or keywords. 2. There are 33 reserved words available in Python. List of keywords in python: and as not assert finally or break for pass class from nonlocal continue global raise def if return del import try elif in while else is with except lambda yield False True None
  • 5. 2. All 33 keywords contains only alphabets symbols. 3. Except the following 3 reserved words, all contain only lowercase alphabet symbols. True False None 4. True and False are Boolean values , For Boolean values, compulsory you need to use capital letter 'T' in True and capital letter 'F' in False. Ex: a = True # Valid A=true # In valid NameError: name 'true' is not defined
  • 6. Statements and Expressions: A statement is an instruction or statement is a unit of code that can be executed by python interpreter. Eg: z = 1 // this iExamples: Y=x + 17 >>> x=10 >>> z=x+20 >>> z 30 s an assignment statement Expression: An expression is a combination of values, variables, and operators which are evaluated to make a new value b. >>> 20 # A single value >>> z # A single variable >>> z=10 # A statement But expression is a combination of variable, operator and value which is evaluated by using assignment operator in script mode. Examples: Y=x + 17 >>> x=10 >>> z=x+20 >>> z o/p : 30 When the expression is used in interactive mode, is evaluated by the interpreter and the result is displayed instantly. Eg: >>> 8+2 10
  • 7. Variables: Variables are nothing but reserved memory locations to store values. That means when you create a variable some space is reserved in memory. • One of the most powerful features of a programming language is the ability to manipulate variables. • A variable is a name that refers to a value. An assignment statement creates new variables and gives them values: • The general format for assigning values is as follows. • Variable name = expression • The equal sign (=) also known as simple assignment operator is used to assign values to variables. • In general format, the operand to the left of the = operator is the name of the variable and operator to the right of the = operator is the expression which can be a value.
  • 8. Eg:1. >>>name=‘python’ >>> number=100 >>> miles=1000.0 >>> name Python >>> number 100 >>> miles 1000 • This example makes three assignment statements. • Integer type assigned to a variable number, float type assigned to a variable miles ,string type value is assigned to a variable name and print the value assigned to these variables.
  • 9. 2. In python not only the value of variable may change during program execution but also the type of data that is assigned. In Python, We don't need to specify the type of variable because Python is a loosely typed language. >>>Century=100 >>> Century = “hundred” >>> Century ‘hundred’ 3. Python allows you to assign value to several variables simultaneously. 1. >>> a=b=c=1 4.Assign multiple values to multiple variables 2.>>> a 1 a,b,c=5,50, 15 3.>>> b >>> a 5 1 >>>b 50 4.>>> c >>>c 15 1
  • 10. Operators in Python • The operator can be defined as a symbol which is responsible for a particular operation between two operands. • Python provides a variety of operators described as follows. • Arithmetic operators : • + (addition) eg: a=20; b=10 then a + b=30 • - (subtraction) eg: a=20; b=10 then a - b=10 • *(multiplication) eg: a=20; b=10 then a * b=200 • / (divide) eg: a=20; b=10 then a / b=2 • %( reminder) eg: a=20; b=10 then a % b=0 • // (floor division) eg: a=24; b=7 then a // b=3 • ** (exponent) eg: a=2; b=3 then a ** b=8
  • 11.
  • 12. Operators in Python • Assignment operators : • = (Assigns to) • += (Assignment after Addition) • -= (Assignment after Subtraction) • *= (Assignment after Multiplication) • /= (Assignment after Division) • %= (Assignment after Modulus) • **= (Assignment after Exponent) • //= (Assignment after floor division)
  • 13.
  • 14. • Comparison operators : • == (Equal to) • != (Not equal to) • <= (Less than or equal) • >= (Greater than or equal) • < (Less than) • > (Greater than)
  • 15. • Logical operators : • and (logical and) • or (logical or) • not (logical not)
  • 16. • Bitwise operators : • & (binary and) • | (binary or) • ^ (binary xor) • ~ (negation) • << (left shift) • >> (right shift) • Membership operators : • in (True, If the value is present in the data structure) • not in (True, If the value is not present in the data structure) • Identity operators : • is (Returns true if both variables are the same object) • is not (Returns true if both variables are not the same object)
  • 17.
  • 19. Comments in Python • In general, Comments are used in a programming language to describe the program or to hide the some part of code from the interpreter. • Comments in Python can be used to explain any program code. It can also be used to hide the code as well. • Comment is not a part of the program, but it enhances the interactivity of the program and makes the program readable. Python supports two types of comments: • Single Line Comment • Multi Line Comment
  • 20. Comments in Python • Single Line Comment: In case user wants to specify a single line comment, then comment must start with ‘#’ Example: # This is single line comment print "Hello Python" Output: Hello Python • Multi Line Comment: Multi lined comment can be given inside triple quotes. Example: '''This is Multiline Comment''' print "Hello Python" Output: Hello Python
  • 21. • Data types: • Data types specify the type of data like numbers and characters to be stored and manipulated with in a program. Basic data type of python are • Numbers • Boolean • Strings • None Numbers: • Integers, floating point numbers and complex numbers fall under python numbers category. They are defined as int, float and complex class in python. 1. integer: • Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length, it is only limited by the memory available. Example: a=10 b=-12 c=123456789
  • 22. 2. float: • Float or "floating point number" is a number, positive or negative, containing one or more decimals. Example: • X=1.0 • Y=12.3 • Z= -13.4 3. complex: • Complex numbers are written in the form , “x+yj" where x is the real part and y is the imaginary part. Example: A=2+5j B=-3+4j C=-6j Boolean: Booleans are essential when you start using conditional statements. Python Boolean type is one of the built-in data types provided by Python, which represents one of the two values i.e. True or False. The boolean values, True and False treated as reserved words.
  • 23. String: • The string can be defined as the sequence of characters represented in the quotation marks. In python, we can use single, double, or triple quotes to define a string. • In the case of string handling, the operator + is used to concatenate two strings as the operation "hello"+" python" returns "hello python". Example: EX : S1=‘Welcome’ #using single quotes S1 Output: ‘Welcome’ print(S1) Output: Welcome Ex: S2=“To” #using double quotes S2 Output: 'to' print(S2) Output: to Ex: S3=‘’’Python’’’ #using triple quotes S3 Output: "'python'" print(S3) Output: 'python‘ Ex: Name1= ‘Hello’ Name2=‘python’ Name1 + Name2 Output: ‘Hellopython’ print(Name1 + Name2) Output: Hellopython
  • 24. Example: a=10 b=“Python" c = 10.5 d=2.14j e=True print("Data type of Variable a :",type(a)) print("Data type of Variable b :",type(b)) print("Data type of Variable c :",type(c)) print("Data type of Variable d :",type(d)) print(“Data type of Variable e :”,type(e)) Output: • Data type of Variable a : <class 'int'> • Data type of Variable b : <class 'str'> • Data type of Variable c : <class 'float'> • Data type of Variable d : <class 'complex'> • Data type of Variable e : <class 'bool'>
  • 25. Indentation: • In Python it is a requirement and not a matter of style to indent the program. This makes the code cleaner and easier to understand and read. • If a code block has to be deeply nested, then the nested statements need to be indented further to the right. • Block 2 and Block 3 are nested under Block 1. 4 white spaces are used for indentation and are preferred over tabs. • Incorrect indentation will result in IndentationError. Block 1 Block 2 Block 3 Block 2, Continuation Block 1, Continuation
  • 26. • Reading Input : • Input() function is used to gather data from the user. • Syntax : variable_name = input([prompt]) • Where prompt is a string written inside parenthesis. • The prompt gives an indication to the user of the value that needs to be entered through the keyboard. • When user presses Enter key, the program resumes and input function returns what the user typed as a string. • Even if the user inputs a number, it is treated as a string and the variable_name is assigned the value of string. 1. >>> person = input(“what is your name?”) 2. What is your name? John 3. >>>person 4. ‘John’
  • 27. Print Output • Print() function allows a program to display text onto the console. • Print function prints everything as strings. >>>print(“Hello World”) Hello World There are two major string formats which are used inside the print() function to display the contents on to the console. 1. str.format() 2. f-strings str.format() method: • The format() method returns a new string with inserted values. • syntax: str.format(p0,p1,p2…..k0=v0, k1=v1,…) • Where p0,p1 are called as positional arguments and k0,k1 are keyword arguments with their assigned values of v0,v1.. • Positional arguments are a list of arguments that can be accessed with an index of argument inside curly braces like {index}. Index value starts from zero. • Keyword arguments are a list of arguments of type keyword = value, that can be accessed with the name of the argument inside curly braces like {keyword}. Eg: country = input(“which country do you live in”) print(“I live in {0}”.format(country))
  • 28. • Print Output Eg: a = 10 b = 20 Print(“the values of a is {0} and b is {1}”.format(a,b)) Print(“the values of b is {1} and a is {0}”.format(a,b)) f-strings: A f-string is a string literal that is prefixed with “f”. These strings may contain replacement fields ,and are enclosed within curly braces { }. Eg: country = input(“which country do you live in”) Print(f”I live in {country}”)
  • 29. Type Conversion in Python: • Python provides Explicit type conversion functions to directly convert one data type to another. It is also called as Type Casting in Python • Python supports following functions 1. int () : This function convert a float number or a string to an integer. • Eg: float_to_int = int(3.5) string_to_int = int(“1”) // number is treated as string print(float_to_int) o/p: 3 print(string_to_int) o/p: 1 will be displayed. 2. float( ) : • This function convert integer or a string to floating point number using the float() function. • Eg: int_to_float = float(8) string_to_float = float(“1”) // number is treated as string print(int_to_float) print(string_to_float) 8.0 1.0 get displayed
  • 30. • The str() Function : The str() function returns a string which is fairly human readable. Eg: int_to_string =str(8) float_to_string = str(3.5) Print(int_to_string) prints ‘8’ Print(float_to_string) prints ‘3.5’ • The chr() Function : This function converts an integer to a string of one character whose ASCII is the same integer used in chr() function. The integer value should be in the range of 0-255. Eg: ascii_to_char = chr(100) Print(“equivalent character for ASCII value of 100 is {ascii_to_char}”) Output: equivalent character for ASCII value of 100 is d An integer value corresponding to an ASCII code is converted to character and printed. (ASCII A-Z =65 to 90 ; a-z = 97 to 122; 0-9 = 48 to 57)
  • 31. • The Complex() Function: • complex() function is used to print a complex number with a real part and imag*j part. • If the first argument for the function is a string, it is interpreted as complex number and the function is called without 2nd parameter. • If imag is omitted, it defaults to zero • Eg: complex_with_string = complex(“1”) – complex_with_number = complex(5,8) Print(f“result after using string in real part{complex_with_string}”) – Print(f”result after using numbers in real and imaginary part{complex_with_number}”) – Output: result after using string in real part (1+0j) – result after using numbers in real and imaginary part (5+8j)
  • 32. The ord() function: • The ord() function returns an integer representing Unicode code point for the given Unicode character. • Eg: 1. unicode_for_integer = ord('4') print(f“ Unicode code point for integer value of 4 is {unicode_for_integer}") Output: Unicode code point for integer value of 4 is 52. The hex() function: • Convert an integer number (of any size) to a lowercase hexadecimal string prefixed with “0x” using hex() function. • 1. int_to_hex = hex(255) • 2. print(int_to_hex ) • Output: 0xff
  • 33. The oct() function: • Convert an integer number (of any size) to an octal string prefixed with “0o” using oct() function. Eg: int_to_oct = oct(255) print(int_to_oct) Output: 0o377. Dynamic and strongly typed language: • Python is a dynamic language as the type of the variable is determined during run- time by the interpreter. • Python is also a strongly typed language as the interpreter keeps track of all the variables types • In a strongly typed language, you are simply not allowed to do anything that’s incompatible with the type of data you are working with. • For example, Parts of Python Programming Language >>> 5 + 10 15 >>> 1 + "a“ Traceback (most recent call last): • when you try to add 1, which is an integer type with "a" which is string type, then it results in Traceback as they are not compatible. • In Python, Traceback is printed when an error occurs.
  • 34. The type() function and is operator: The syntax for type() function is, type(object) The type() function returns the data type of the given object. 1. >>> type(1) <class ‘int’> 2. >>> type(6.4) <class ‘float’> 3. >>> type("A") <class ‘str’> 4. >>> type(True) <class ‘bool’> The type() function comes in handy if you forget the type of variable or an object during the course of writing programs.