Unit 2 Introduction To Python About Python
Unit 2 Introduction To Python About Python
INTRODUCTION TO PYTHON
ABOUT PYTHON
Python is an easy to learn, general purpose, powerful programming language.
It was created by Guido van Rossum during 1989
Python is a high-level, interpreted, interactive and object-oriented scripting language.
Python is designed to be highly readable.
Python Indentation
Indentation refers to the spaces at the beginning of a code line.
Python uses indentation to indicate a block of code.
Digits -- 0-9
TOKENS
The smallest individual unit in a program known as Token
Python have the following Tokens:
1. Keywords
2. Identifiers
3. Literals
4. Operators
5. Punctuators
1. KEYWORDS
Keywords are reserved words that have special meaning in Python
language.
They are reserved, they can’t be used as identifiers.
assert finally or
def if return
elif in while
else is with
2. IDENTIFIERS
A Python identifier is a name used to identify a variable, function, class,
module or other object.
RULES FOR USING IDENTIFIERS
An identifier starts with a letter A to Z or a to z or an underscore (_)
followed by zero or more letters.
Identifier must not be keyword
Python does not allow punctuation characters such as @, $, and % within
identifiers.
Python is a case sensitive programming language.
Thus, Manpower and manpower are two different identifiers in Python.
3. LITERALS
Literals are data items that have a fixed value.
Also referred as constants.
Different types of literals are:
1) String Literal
2) Numeric Literal
3) Boolean Literal
4) Special Literals
5) Literal Collections
1. String literals
There are only two boolean literals in Python. They are true and false.
In python, True represents the value as 1 and False represents the value
as 0.
4. Special literals
Python contains one special literal (None). ‘None’ is used to define a null
variable.
If ‘None’ is compared with anything else other than a ‘None’, it will
return false.
5. Literal Collections
There are four different types of literal collections
1.List literals
2. Tuple literals
3. Dict literals
4. Set literals
Python Datatypes
Python data types are divided into two categories, mutable data types and
immutable data types.
1. Mutable Data Types: Data types in python where the value assigned to a
variable can be changed Eg: List, Dictionary, Set
2. Immutable Data Types: Data types in python where the value assigned to a
variable cannot be changed Eg: Numeric, String, Tuple
4. OPERATORS
Operators are used to perform operations on variables and values
1. Arithmetic operators
2. Relational operators
3. Assignment operators
4. Logical operators
5. Membership operators
6. PUNCTUATORS
These are the symbols that used in Python to organize the structures,
statements, and expressions. Some of the Punctuators are: [ ] { } ( ) @ -=
+= *= //= **== = , etc.