SlideShare uma empresa Scribd logo
1 de 34
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.

Mais conteúdo relacionado

Semelhante a parts_of_python_programming_language.pptx

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
 

Semelhante a parts_of_python_programming_language.pptx (20)

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
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
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
 
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
 
Token and operators
Token and operatorsToken and operators
Token and operators
 

Mais de 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
 
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
 
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
 

Mais de 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
 

Último

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.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.