Python programming unit-2 identifiers and keywords.pptx
AmyPrasannaTella1
9 views
40 slides
Oct 18, 2025
Slide 1 of 40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
About This Presentation
Python programming identifiers and keywords
Size: 483.56 KB
Language: en
Added: Oct 18, 2025
Slides: 40 pages
Slide Content
Python programming unit-II
Contents Python identifiers(literals) Reserved keywords Variables Comments Lines and indentations Quotations Assigned values to variables Datatypes in python Mutable vs Immutable
Contents Fundamental Datatypes Number Datatypes Inbuilt functions in Python Datatype conversions Python operators
Python Identifiers: Identifier is a name used to identify a variable, function, class or a module. It can start with letter A to Z (or) a to z, an underscore(_) followed by zero or more letters, underscores and digits(0-9). It doesn’t allow special characters like @,$,% with identifiers. These are case sensitive i.e., Manpower and manpower are two different identifiers.
Reserved Keywords: These are the reserved words used in Python. These names cannot be used as either identifiers or constants or variables. False Await Else Import pass None Break Except In raise True Class Finally Is return And Continue For Lambda try As Def From Nonlocal while Assert Del Global Not with Async Elif If Or yield
How to get list of keywords in Python: >>> import keywords >>> print ( keywords.kwlist )
Variables: Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. It is the name use to declare any value either it can be int, float, complex or any other type. It is created at the moment we assign a value and refers to a memory location. String variable can be declared either by ‘ ’ or “ ”. Eg : a=10 a=“name” a=10.5
Rules for Variables: A variable can have a short name (like x and y) or a more descriptive name (age, carname , total_volume , etc ) A variable name mus t start with a letter or the underscore character. A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores(A-Z,0-9 and _). Variables names are case-sensitive( age,Age and AGE are three different variables).
Comments: it helps the beginners to understand any tougher logics and also to recollect the logic they have written. In c programming comments starts with /* and ends with */. In python comments starts with # Eg : # printing # hello world Eg : ””” it is also an example of multi line comments”””
Lines and Indentations: Most of the programming languages like c, c++, and java use braces {} to define a block of code. Python uses indentation Python doesn’t support braces to indicate block of codes for class and function, definitions or flow control. Block of codes are denoted by line indentation. All the continuous lines indented with same number of spaces would form a block. Python strictly follows indentation rules to indicate the blocks. Incorrect indentation will results indentation error.
Example: if 5>2: Print(“five is greater than two!”) This gives an error as there is an indentation missing. if 5>2 : print(“five is greater than two!”)
Quotations: Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string. The strings created by using single and double quotes are the same. In other words, we can use single and double quotes interchangeably when we declare a string.
Assigned values to variables: Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. eg : n=100 This is read or interpreted as “n is assigned the value 100”. N can be used in a statement or expression and its value will be substituted. Later, if you change the value of n and use it again, the new value will be substituted instead
Data types in Python: Variables can hold values, and every value has a data-type. Python is a dynamically typed language Python provides us the type() function, which returns the type of the variable passed. Type represents the kind of value and determines how the value can be used.
Types of datatypes: There are 5 basic types of datatypes as mentioned: Numeric Dictionary Boolean Set and Sequence type
MUTABLE vs IMMUTABLE: Mutable : These are of type list , dict , set . Custom classes are generally mutable . list=[‘orange’, ‘pink’, ‘yellow’] list[0]= ‘red’ list[-2]= ‘blue’ Immutable: These are of in-built types like int, float, bool, string, unicode , tuple. In simple words an immutable object can’t be changed after it is created. Eg : tuple1=(0,1,2,3) tuple1[0]=4 Print(tuple1)
Fundamental Datatypes: These datatypes are created by numerical values. Integer Floating number Complex numbers Boolean and Strings
INTEGER: represented as <class ‘int’>. Consists of either positive or negative whole numbers. Python2 version has int, long but python3 version has only int. There is not length of the integer value unlike other datatypes. Eg : a=1234 b=(-4567) c=0 d=(123456789123456789123456788+1)
FLOATING NUMBER: Represented as <class ‘float’>. Generally specified with a decimal point values. It also accepts a scientific notation like a character e/E. Eg : a=4.2 b=4. or .2 c= .4e7 d= 4.2e-4
COMPLEX NUMBERS: Represented as <class ‘complex’>. these are ordered pair i.e., a+bJ or a+bj . Where j is the imaginary number i.e., square root of -1. Here the values are considered as a floating numbers. Eg : a=2-14j b= 2.0+3j
BOOLEAN: Represented as <class ‘bool’>. It is the datatype with two built-in values, “True” or “False”. Non-Boolean objects can also be evaluated in Boolean context. Eg : a=6;b=7 a>b print(type(True)) print(type(False)) print(type(false))
STRINGS: Represented as <class ‘str’>. These are arrays of bytes representing Unicode characters. These are the collection of characters in a ‘’,””,’’’. Here we don’t have any datatype like char in python. How to create a string? How to access the values of a string? M A L L A R E D D Y
Example: How to create a string string1=(“ malla reddy ”) print(“string with the use of double quotes:”) print(string1) 2. How to access elements : string1=(“ malla reddy ”) print(string1[4]) print(string1[-7])
Number data types: We have 4 types in number datatypes: Binary Decimal Octal and Hexadecimal.
Binary: it is a number system with base 2 and computer can understand only binary numbers(0 and 1). Represented as 0b. Decimal: is most widely used with base 10. Represented from 0 to 9. Octal: it is number system with base 8 and represented as 0o. Hexadecimal: a number system with base 16 and represented as 0x.
Inbuilt Functions: The Python built-in functions are defined as the functions whose functionality is pre-defined in Python. The python interpreter has several functions that are always present for use.
Datatype conversions: There are two types of conversions: Implicit: automatic conversion eg : a=5 print(type(a)) 2. Explicit: it requires user involvement. This can be done with the help of int(), str(), float() etc.,
EXPLICIT CONVERSIONS: Converting number to string: using str() function. Eg : a=10 s=str(a) print(s) print(type(s)) Converting string to number: using int(), float() function. Eg : s= ‘50’ n=int(s) f=float(s) print(n) print(f) print(type(n)) print(type(f))
Example: Converting floating point to integer: using int() function. Eg : f=10.0 n=int(f) print(n) print(type(n)) Converting integer to float type: using float() function. Eg : n=10 f=float(n) print(f) print(type(f))
Converting list to a tuple and tuple to a list: using list(), tuple() function. Eg : t=(1,3,2,4) l=[5,6,7,8] T=tuple(l) L=list(t) print(T) print (L) print(type(T)) print(type(L))
Python Operators: The operator can be defined as a symbol which is responsible for a particular operation between two operands Python provides a variety of operators. Arithmetic Operators Comparison Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators and Identity Operators.
Arithmetic Operators: Arithmetic operators are used to perform arithmetic operations between two operands.
Comparison Operators: Comparison operators are used to comparing the value of the two operands and returns Boolean true or false accordingly.
Assignment Operators: The assignment operators are used to assign the value of the right expression to the left operand .
Logical Operators: The logical operators are used primarily in the expression evaluation to make a decision.
Bitwise Operators: The bitwise operators perform bit by bit operation on the values of the two operands.
Membership Operators: Python membership operators are used to check the membership of value inside a Python data structure. If the value is present in the data structure, then the resulting value is true otherwise it returns false.
Identity Operators: The identity operators are used to decide whether an element certain class or type.