0% found this document useful (0 votes)
13 views

Unit 2 Introduction To Python About Python

The document introduces Python, describing it as an easy to learn, general purpose and powerful programming language. It discusses working with Python interactively or via script mode and covers Python syntax including indentation, character sets, tokens, literals, datatypes and operators.

Uploaded by

toebitescoups
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Unit 2 Introduction To Python About Python

The document introduces Python, describing it as an easy to learn, general purpose and powerful programming language. It discusses working with Python interactively or via script mode and covers Python syntax including indentation, character sets, tokens, literals, datatypes and operators.

Uploaded by

toebitescoups
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIT 2

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.

WORKING WITH PYTHON


We can work with Python mainly in two ways:
 Interactive Mode is used when a user wants to run one single line or one block of
code. It runs very quickly and gives the output instantly
 Script Mode is used when the user is working with more than one single code or a
block of code

Python Indentation
 Indentation refers to the spaces at the beginning of a code line.
 Python uses indentation to indicate a block of code.

PYTHON CHARACTER SET

 Letters -- A-Z, a-z

 Digits -- 0-9

 Symbols -- + - * / ! @ # $ % ^ & * ( ) {} [ ] ; : ‘ “ < > = //

 White Space – Blank Space, Tab, Enter Key, New line

 Other Characters – all ASCII characters and Unicode Characters

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.

and exec not

assert finally or

break for pass

class from print

continue global raise

def if return

del import try

elif in while

else is with

except lambda yield

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

 A string literal can be created by writing a text(a group of Characters )


surrounded by the single(”), double(“”), or triple quotes.
 Character literal- It is also a type of string literals where a single character
surrounded by single or double-quotes.
2. Numeric literals
 They are immutable and there are three types of numeric literal :

1. Integer literals- Both positive and negative numbers including 0.


There should not be any fractional part
2. Float- These are real numbers having both integer and fractional
parts.
3.Complex- The numerals will be in the form of a+bj, where ‘a‘ is
the real part and ‘b‘ is the complex part.
3. Boolean 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.

You might also like