Python Notes: Developed By:-Guido Van Rossum in February 1991

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

Python Notes

Developed by:- Guido Van Rossum in


February 1991
Introduction
a) Python programing language is influenced with two
programming language:
1. ABC language, a teaching language created as
a replacement of BASIC
2. Modula-3.
b) Python is easy to learn, powerful object-oriented
language.
c) Python is very high-level programming language
d) It is yet powerful as many other middle level not
so high-level language like C,C++,Java etc.
Advantages of Python
programming language
• 1. Easy to use
• Python is compact and very easy to use object-oriented
language with simple syntax rules.
• 2. Expressive language
• Python’s expressive means it is more capable to expressing
the code’s purpose than many other languages.
• Example:
• a=3
• B=5
• C=a+b
• Print(c)
• 3. Interpreted language
• Python is a interpreted language, not a compiled language. It execute
the
code line by line at a time.
• 4. cross platform language
• Python can run equally well on variety of platform like –
windows/Linux/mac
5. Free and open source
Python language is freely available without any cost and it is source
code is also available
6. Variety of usage/applications
Web development, gui programs game development, database
applications etc.
Disadvantages of python
programming language
1. Not the fastest language
Python is little weaker though it offers faster development times but
execution-times are not that fast compared to some compiled
languages
2. LESSER LIBRARIES THAN C,JAVA,PERL
3. NOT EASILY CONVERTIBLE
Python has disadvantage when it comes to translating a program into
another programming language. This is because most language have
structured defined syntax
Python programming
language character set
• Character set is a set of valid characters that a language can
recognize. A character represents any letters, digit or any
other symbol
1. Letters (A-Z, a-z)
2. Digits (0-9)
3. Special Symbols (+-*/~!@#$%^&*()_={}|\[];’:”,.<>/?)
4. Whitespaces (Blank space, tabs, carriage return, newline)
5. Other characters (python can process all ASCII and
Unicode character as part of data or literals )
Smallest individual unit in a program is known as token or a
lexical Unit
1. keywords

2. identifiers (Names)

Tokens 3. Literals

4. Operators

5. Punctuators
keywords
False assert elif for in or while
None break else from is pass with
True class expect global lambda raise yield
•HAVING SPECIAL MEANING
RESERVED BY and continue finally if nonlocal return
PROGRAMMING LANGUAGE
as def del import not try
•AND MUST NOT TO BE USED
AS IDENTIFIERS NAMES
Identifiers (names)
identifiers are used as the general terminology for the names
given to different part of program viz. variables, object, classes,
functions, list, dictionaries etc.
Identifiers rules
1. Identifier is an arbitrarily long sequence of letters and
digits
2. The first character must be a letter; the Underscore(_)
counts as a letter.
3. Upper and lower-case letters are different. All characters Valid example of identifier Invalid example of identifier
are significant.
4. The digits 0-9 can be part of the identifier expect first
character. Myfile, DATE9_7_7_77, DATA-REC (Contains hyphen (-))
5. Identifiers are unlimited in length. Case is significant i.e., Z2T0Z9, MYFILE, 23LCCT (starting with digit)
python is case sensitive. _DS, _PYTHON_3L, _CHK, Break (reserved keyword)
6. An identifier must not be a keyword of python. FILE123 My.file (contain special character dot(.)
7. Identifier can't be contain any special character expect for
underscore(_).
Literals/Values
Literals are the data items that a fixe value.
1. String Literals
2. Numeric Literals
3. Boolean Literals
4. Special Literal NONE
5. Literal Collections
String Literals

Text enclosed in single or double quotes forms a


string literal in Python.

Example: “python”, ‘earth’, “helloworld”, “123456”,


“Amy’s”, ‘1-x-0-w-25’

Types of String
1. Single-line String
2. Multi-Line String
1. Single-Line String

String that you create by enclosing text in single(‘ ’)


or double (“ ”) quotes are normally single-line
string. They must be terminate in one line.

Example:
a=‘Hello World’
2. Multi-Line String
a) By adding a backslash at the end of normal single-
quote/double-quote string
Example: a= ‘hello \
world’
b) By adding the text in triple quotation marks. (No
backslash needed at the end of line).
Example: a=‘ ‘ ‘ Hello
world
Python’ ’ ’
Numeric Literals

Int (signed integers) Often called just integers or ints, are


positive or negative whole number with no
decimal points

Float (floating point real values) Float represent real number and are
written with a decimal point dividing the
integer and fractional parts

Complex (complex numbers) are the form of a+bJ, where a & b are
floats and J or j represents . a is real part of
number and b is imaginary part.
• Integer Literals are whole numbers without any fractional part. It may
contains either (+) or (-) sign. Number with no sign is assumed to be
positive

 Decimal Integer Literals: consisting sequence of digit is to be taken to be


decimal. E.g. 1234, -5, +45, -69

Integer  Octal Integer Literals: sequence of digit starting with 0o(digit zero is
followed by letter o )is to be taken an octal integer,

Literals e.g. 8 will be written as 0o10 as octal integer


Octal Value can be contain only digit 0-7; 8 & 9 are invalid digits in octal
integers.
 Hexadecimal Integer Literals: sequence of digit preceded by 0x or 0X is
taken to be Hexadecimal Integer
e.g. 12 will be written as 0XC as hexadecimal
Hexadecimal value can contains digits 0-9 and letters A-F only
• Floating literals are also called real literal. Real numbers having fractional

Floating
parts
1. Fractional form : A real literals in fractional form consists of signed or
unsigned digits including a decimals point between digits
point 2. Exponent Form: A real literal in exponent form consists of two parts:
mantissa and exponent.
Literals e.g. 5.8 can be written as 0.58x10^1 = 0.58E01, where mantissa part is 0.58 and
exponent part is 0
Boolean Literal
A Boolean literal in python is used to represent one of the two Boolean
values i.e., True or False
Special Literal NONE
Python has one special literal, which is NONE literal is used to
indicate absence of value. It is also used to indicate the end of list in
Python.

Note: Python support literal collection also such as tuples and list
etc. but covering these here would make the discussion too complex
for the beginning.
• Operators are tokens that trigger some
computation/ action when applied to
variables and other objects in an expression.
• Variables and object to which the
Operators computation is applied, are called operands,

• Unary Operators
• Binary Operators
• Arithmetic operators
• Bitwise operators
• Shift operators
• Identity operators
• Relational operators
• Logical operators
Unary Operators
• Unary operators are those that require one operand
to operate upon.
 + (Unary Plus)
 - (Unary minus)
 ~ (Bitwise complement)
 Not (logical negation)
Binary Operators
Binary operators are those operators that require two operands to
operate upon.
Arithmetic operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder/ Modulus
** exponent (raise to power)
// Floor division
Bitwise operators:
& Bitwise AND
^ Bitwise exclusive OR (XOR)
| Bitwise OR

Shift Operators:
<< Shift left
>> Shift right

Identity Operators:
Is is the identity same ?
Is not is the identity not same ?
 Relational Operator
< Less than
< Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to

Logical operators
and Logical AND
or Logical OR

Membership Operators
In Whether variable in sequence
not in Whether variable not in sequence
Assignment Operators
= Assignment
/= Assign quotient
+= Assign sum
*= Assign product
%= Assign remainder
-= Assign difference
**= Assign Exponent
//= Assign Floor division
Punctuators
Punctuators are symbols that are used in programming languages to organize
programming-sentence structure, and indicates the rhythm and emphasis of
expressions, statements, and program structure

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

You might also like