Introduction-Single Value Datatype
Introduction-Single Value Datatype
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.
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.
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
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
5. Python document says that you can have an identifier with unlimited length (according to ISR maximum 32 character)
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
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
1. Special character (!@#$%^&* including space …)are not allowed except underscore ( _ ).
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( )
• 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.
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.
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
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