0% found this document useful (0 votes)
11 views18 pages

ch-1

Uploaded by

Ayush Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views18 pages

ch-1

Uploaded by

Ayush Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

What is Python?

Python is a popular high level


programming language. It was
created by Guido van Rossum, and
released in 1991.
Token
The smallest individual unit in a
program is known as Token.
Python has the following tokens
• Keywords
• Identifiers
• Literals
• Operators
• Puntuators
Identifiers
Identifiers are the names given to different
parts of a program like variables, objects,
classes, functions, list, dictionaries etc.
Naming Rules for Python Identifiers
• The first character of the variable must be an alphabet or
underscore( _ )
• All the characters except the first character may be an alphabet of lower
case(a-z), uppercase (A-Z), underscore or digit(0-9).
• Identifier name must not contain any white space or special
character(!,&,#,@,% etc).
• Identifier name must not be a keyword defined in Python.
String Literals
• String Literal is a sequence of characters surrounded by quotes(single,
double or triple quotes). String literals can be single line strings or
multiline strings.
For Example-
>>>Text=“hello world” single line string

>>>Text1=“hello\ Multi line string

world”
>>>Text2=‘’’hello No backslash needed
world”’
Escape sequences
In Strings, you can insert non-graphic character through escape
sequence.
Escape sequences What it does
\\ Backslash ( \ )

\’ Single quote( ‘)

\” Double quote( “)

\a ASCII Bell

\b Backspace

\n New Line Characters

\r Carriage return

\t Tab
Numeric Literals
Numeric Literals are numeric values and these can be
of 3 types
• Int: often called integers or ints, which can be positive or negative
number with no decimal points.
Ex- 48, -30
• Float: Float represents real number and are written with a decimal
point.
Ex-10.5,-5.2
• Complex number: Complex number are of form of a+bj, where a and
b are floats and j represents , which is an imaginary number, a is the
real part of the number, and b is the imaginary part.
Boolean Literals
Boolean Literals in Python is used to represent one of the two Boolean
values i.e. True or False.
For ex-
a=2==3
print(a)
Output- False
Special Literal
Python has one special literal, which is None. The None literal is used
to indicate absence of value. It is also used to indicate the end of list in
Python.
For ex-
a=None
print(a)
Output: None
Operators
Operators are the symbols that perform arithmetic and logical
operations on operands and provide a meaningful result.
An operator need one or more operands to perform any operations.
The valid combination of operand and operators makes an
expression which return computed result.

operators

Sum=a+b Expression

operands
Python support several types of
operators
• Arithmetic Operators (+, -, *, /, %, **, //)
• Relational Operators (<, >,==, >=, <=, !=)
• Identity Operators (is, is not)
• Logical Operators (and, or, not)
• Bitwise Operators (&, ̂ I)
• Membership Operators (in, not in)
• Assignment Operators (=, +=, /=, -=, %=, **=, //=)
Punctuators
Punctuators are the symbols that are used in programming languages
to organize sentence structure and indicates the rythms and emphasis
of expression, statements and program structure.
Most common Punctuators are-

‘ “ # \ () [] {} @ , : , . =

You might also like