Chapter-3 BRIEF OVERVEIW OF
PYTHON
Python-character set
• Character Set-is a group of letters or signs which
are specific to a language.
• Character set includes letter, sign, number,
symbol.
– Letters: A-Z, a-z
– Digits: 0-9
• – Special Symbols: _, +, -, *, /, (, ), {, } . . . Etc.
– White Spaces: blank space, tab,
Token
• Token- is the smallest unit of any
programming language. It is also known
as Lexical Unit. Types of token are-
i. Keywords
ii.Identifiers (Names)
iii.Literals
iv.Operators
v. Punctuators
Keyword
• Keywords are reserved words. Each keyword
has a specific meaning to the Python
interpreter. As Python is case sensitive,
keywords must be written exactly as given in
Table
Identifiers
• In programming languages, identifiers are names
used to identify a variable, function, or other entities
in a program.
• The rules for naming an identifier in Python are as
follows:
• The name should begin with an uppercase or a
lowercase alphabet or an underscore sign (_).
• This may be followed by any combination of
characters a-z, A-Z, 0-9 or underscore (_).
• Thus, an identifier cannot start with a digit.
• It can be of any length. (However, it is
preferred to keep it short and meaningful).
• It should not be a keyword or reserved word.
• We cannot use special symbols like !, @, #, $,
%, etc. in identifiers.
Variables
• Variable is an identifier whose value can
change.
• For example variable age can have different
value for different person.
• Variable name should be unique in a program.
Value of a variable can be string (for example,
‘b’, ‘Global Citizen’), number (for example
10,71,80.52) or any combination of
alphanumeric (alphabets and numbers for
example ‘b10’)
• In Python, we can use an assignment statement to
create new variables and assign specific values to them.
• gender = 'M'
• message = "Keep Smiling"
• price = 987.9
• Marks=50
• Name=“Ram”
• Variables must always be assigned values before they
are used in the program, otherwise it will lead to an
error. Wherever a variable name occurs in the program,
the interpreter replaces it with the value of that
particular variable.
Write a Python program to find the sum of two numbers.
#Program 3-2
#To find the sum of two given numbers
num1 = 10
num2 = 20
result = num1 + num2
print(result)
#print function in python displays the output
• Output:
• 30
Write a Python program to find the area of a rectangle given that its length is 10 units and breadth is 20 units.
Literals / Values
• Literals are often called Constant Values.
• Python permits following types of literals -
– String literals - “Pankaj”
– Numeric literals – 10, 13.5, 3+5i
– Boolean literals – True or False
– Special Literal None
String Literals
• String Literal is a sequence of characters that can be a
combination of letters, numbers and special symbols,
enclosed in quotation marks, single, double or triple(“ “ or ‘ ‘
or “’ ‘”).
• In python, string is of 2 types-
– Single line string
• Text = “Hello World” or Text = ‘Hello World’
– Multi line string
• Text = ‘hello\ Text = ‘’’hello
or world’ word ‘’’
Numeric Literals
• Numeric values can be of three types -
– int (signed integers)
• Decimal Integer Literals – 10, 17, 210 etc.
– float ( floating point real value)
• Fractional Form – 2.0, 17.5 -13.5, -.00015 etc.
• Exponent Form - -1.7E+8, .25E-4 etc.
– complex (complex numbers)
• 3+5i etc.
Boolean Literals
• It can contain either of only two values – True or False
A= True
B=False
Special Literals
• None, which means nothing (no value).
X = None