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

Introduction-Single Value Datatype

Uploaded by

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

Introduction-Single Value Datatype

Uploaded by

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

Introduction

Saturday, October 07, 2023 9:47 PM

Introduction
• Python is a general purpose high level programming language.
• Python was developed by Guido Van Rossum in 1989 while working at National Research Institute in the Netherlands.
• The official Date of Birth for Python is : Feb 20th 1991.
• Python is recommended as the first programming language for beginners.

Application areas of Python:


1. For developing Desktop Applications
2. For developing web Applications
3. For developing database Applications
4. For Network Programming
5. For developing games
6. For Data Analysis Applications
7. For Machine Learning
8. For developing Artificial Intelligence Applications

Note:(Internally Google and YouTube use Python coding NASA and Network Stock Exchange Applications developed by
Python. Top Software companies like Google, Microsoft, IBM, Yahoo using Python.)

Features of Python:
1. Simple and easy to learn:
Python is a simple programming language. When we read a Python program, we can feel like reading English
statements.
2. Freeware and Open Source:
We can use Python software without any license and it is freeware.
3. High Level Programming language:
Python is a high level programming language and hence it is a programmer friendly language.
4. Platform Independent:
Once we write a Python program, it can run on any platform without rewriting once again.
5. Dynamically Typed:
In Python we are not required to declare type for variables. Whenever we are assigning the value, based on value, type will b e allocated
automatically.
6. Interpreted:
In python all code is executed line by line, We are not required to compile Python programs explicitly. Internally Python int erpreters will
take care of that compilation.
7. Extensive Library functions:
Python has a rich inbuilt library. Being a programmer we can use this library directly and we are not responsible for impleme nting the
functionality.

Introduction of python Page 1


Identifier
Saturday, October 07, 2023 9:51 PM

IDENTIFIER: It is a name given by the user to represent a function, class, module and other objects.
i,e., If you assign some name to a programable entity. then it is technically called as a Identifier.
To check an identifier is valid or not:
Syntax : 'identifier_name'.isidentifier

RULES OF IDENTLEIER:
1. Identifier Should start with alphabets or underscore( _ ).
Ex: abc = 23
'abc'.isidentifier() o/p : True

2. It can contain alphanumerical but should not start with number.


Ex: abc123 = 34
'abc123'.isidentifier() o/p : True
123abc = 34 error
'123abc'.isidentifier() o/p : False

3. Special character (!@#$%^&* including space …)are not allowed except underscore ( _ ).
Ex: _abc = 90
'_abc'.isidentifier() o/p : True
_ = 90
'_'.isidentifier() o/p : True
@abc = 34 error
'@abc'.isidentifier() o/p : False
ab@c = 34 error
'ab@c'.isidentifier() o/p : False

4. We can't assign any value to keyword.


Ex: and = 23 error

5. Python document says that you can have an identifier with unlimited length (according to ISR maximum 32 character)

6. Names are case sensitive.

Introduction of python Page 2


keyword
Saturday, October 07, 2023 10:07 PM

KEYWORDS:
In Python some words are reserved to represent some meaning or functionality. Such types of words are called Key words.
SYNTAX To display all keywords in IDLE
>>>import keyword
>>>keyword.kwlist

• To check an keyword is valid or not:


Syntax : keyword.iskeyword('name')
o/p will be either True or False

• Special keyword : False,True,None


• We can't assign value to keywords

Introduction of python Page 3


Variables
Saturday, October 07, 2023 10:08 PM

VARIABLES:
Variable is a named memory block where we are going to store some values.
SYNTAX:- VAR_NAME=VALUE
• If there are more than one word in variable then we use underscore( _ ) to separate them

RULE OF CREATING VARIABLES:

1. Variables Should start with alphabets or underscore( _ ).

1. It can contain alphanumerical but should not start with number.

1. Special character (!@#$%^&* including space …)are not allowed except underscore ( _ ).

1. We can't assign any value to keyword.

1. Names are case sensitive.

Memory location/block :
• If we want to find memory address/location of a value we use id( )
• [id()-> It is a function which is used to check the address of a given variable.]
• If we want in hex format memory address than we use hex( )

Memory management in variable :

RAM : random access memory


It contains stack, heap, mainframe
Stack : it is used to store variable in organized manner.
Heap : it is stored value/object in randomly
Mainframe : it is use for execution

• As soon as control see variable creation process, ram will divide the memory into variable space/stack and value space/heap.
• Control will pic the value and it store into value space/heap , address will be given and that will get stored with respect variable name in
variable space/stack.

MULTIPLE VARIABLE CREATION :


• It is a phenomenon of creation multiple variable in a single line
SYNTAX:- VAR1,VAR2,…….,VAR n =VALUE1,VALUE2,…..,VALUE n
• In multiple variable creation the number of variables is equal to number of values

Introduction of python Page 4


• In multiple variable creation the number of variables is equal to number of values
○ Ex: a,b,c = 10,20,30
a,b,c,d = 10,20,30 error
a,b,c = 10,20,30,40 error

Introduction of python Page 5


Datatype
08 October 2023 09:02

Data types:
• Data type is used to specify the type and size of the value present inside the variable.
• In Python we are not required to specify the type explicitly. Based on the value provided, the type will be assigned automatically to a
variable.
• Based on the size of the value data type get classified into two categories.

1. Single value data type:


It is a data type where we are going to store a single value into a single variable.(immutable)
Ex:a=10
2. Multi value /collection data type:
It is a data type where we are going to store multiple value int a single variable.(pre defined data structure)
Ex:a=10,20,30……

Introduction of python Page 6


Introduction of python Page 7
Single value data type
08 October 2023 11:00

Integer(int):Integer in a real number without decimal point.


Ex: -∞….-2,-1,0,1,2,3….+∞
• Integer can be positive or negative.
• Each and ever data will be having two type of values
1. Default value :it is a initial value and which will be internally equal to false.
Ex:0=default value =False
2. Non-default value: other than default value all the value are considered as non default value, which in internally equals to true
Ex: except ‘0’ all are non default value
• Zero(0) in default value for integer.
• Type( ):it in a function which in used to get the type of the value stored inside the variable and the syntax used in “type(v ariable/value)”.
• Ex:>>>n=72
Var space Value space
0X21 72
n 0x21

Id(n) #23456
type(n) <class 'int’>
>>>b=0
type(b) <class ‘int’>

Float:
• Float in a real number with decimal point.
• Float can be either +ve or -ve number.
• 0.0 in the default value for float.
• In float decimal point in very important we can ignore decimal value and floating values.
Ex: a=34.67
Var space Val space
Ox21 34.67
a Ox21
>>>id(a) 2345
>>>type(a) <class ‘float’>
>>> . syntax error

Complex :
• Complex in number which in a combination of both real and imaginary terms.
OR
• The number which in the form a±bj in called as complex number.
Var space Val space
Ox21 3+4j
a Ox21
j=-1
A and b=int/float
j=imaginary part
ex: a=3+4j

• In complex number we can’t use any other alphabet characters as imaginary number except ‘j’ or’J’
• If we use ‘j’ internally it will get converted into ‘j’.
• In complex number we can’t rearrange the value of b&j.
Ex: a+bj correct
>>>a+jb wrong
• It in not possible to mention an independent ‘j’.
Ex:>>> j
• ‘0j’in the default value for complex number.
Ex:7+1j 7+1j

Introduction of python Page 8


7j+8 8+7j
-6+7j -6+7j
45+6i syntax error
c=1+2j
type(c) <class ‘complex’>
4+7q syntax error

Boolean(bool):
• Boolean is a data type which consists of only two values. i.e.. Ture & False.
• True is internally considered integer ‘1’ and False is considered as integer ‘0’.
• Since there are only two values ‘True’ in consider as non default value & ‘False’ in default value.
Var space Value space
Ox11 True
a Ox11
0x22 False

b OX22
• As a value while creating variable
>>>a=True
>>>b=False
• As a resultant while checking the condition.
>>>a=10
>>>b=5
>>>a>b True
>>>type(a) <class ‘bool’>
>>>type(b) <class ‘bool’>
>>>a=10
>>>b=27
>>>a==b False
>>>a<b True

Introduction of python Page 9

You might also like