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

Language Fundamental

----------------------
Identifiers
-------------
A name in python program is called as identifer
It can be a variable name or class name or function name or method name

eg:
a=10 #-->a is a identifer/name
class Demo #--> class name Demo is a identifer
def func1 # func1 is a function name and it is a identifer

Rules to define the identifiers in python


-------------------------------------------
1. only alphabets must be used
both upper case and lower case

2. we can use the digits (0-9)

3. we can use underscore symbol (_)

Note : apart from these combination if we are using any other things we will get
syntax error

eg;
sagar=10 #valid
$agar=10 #invalid
print($agar)

* Identifiers should not start with the digits


eg;
sachin =10 #valid
sachin10 = 100 #valid
sac10hin=98 #valid
10tendulker #invalid
print(10tendulker)

* in python identifiers are case sensitive


eg;
sachin=10
SACHIN=20
Sachin=30
--> in the above example all the 3 names are taken as indivual identifiers

Note:
sachinTendulker =10 #--> camel case convention in JAVA
sachin_tendulker =10 #--> snake case convention in Python

* There is no length limit for the identifers


but it is suggested that to use max of 15 characters

eg;
abcdefghijklmnopqrstuvwxyz=10 #valid
print(abcdefghijklmnopqrstuvwxyz)

number_value=10 #valid
print(number_value)
* we can not use the reserved keywords as identifers
eg;
name='sagar' #valid
for = 10 #invalid
if =20 #invalid
def = 30 #invalid
class =90 #invalid
try =50 #invalid

task
------
1sachin10tendulker -->invalid
_abc_def -->valid
ca$h = 100 -->invalid
Integer = 10 -->valid
int= 10 -->valid

Note :
------
1. if identifer is starting with _ symbol then it indicates as private member
eg;
_name= 'sagar'

2. if identifer is starting with __ symbol then it indicates as strongly


private member
eg;
__age=16

3.if identifer is starting with __ and ending with __ symbol then it indicates
magical methods
eg;
__init__

Reserved Keywords
-------------------
In python some words are reserved to represent some meaning or functionality
Such type of words are called as Reserved keywords

*There are 35 keywords are there in python

eg;
import keyword
keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break',
'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for',
'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or',
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']

Note:
-------
1. all the keywords are alphabets [lower case]
except
-->False None True

eg;
a= True
#a= TRUE #invalid
a= 'TRUE'
#a= true
a= 'true'
print(a)

eg;
#True =10 #invalid
TRUE =10 #valid
'TRUE' =10 #invalid

print('TRUE')

Data Types
-------------
Data type represents the type of the data
In python we are not required to specify the datatype explicitly like java
Based on the value provided to the variable datatype will be decided automativally
Hence python is called as "Dynamically typed language"

eg;
a=10 --> valid in python
int a=10 --> valid in java

Python contains 14 datatypes


Python contains the fallowing datatypes
#Fundamental datatypes
-----------------------
1.int
2.float
3.complex
4.bool
5.str

#intermediate datatypes
------------------------
6.bytes
7. bytearray
8. range

Advanced datatypes
-------------------
9. list
10. tuple
11. set
12. frozenset
13. dict

extra
-------
14. None

Note : there are few basic and importent built in functions


are there in python such as :
eg;
a=10
print(a) #10
#to display any data on the screen we need print function

a=10
print(type(a)) #<class 'int'>
#to check the datatype of the data we use type function

a=10
print(id(a))
#to check the memory address of the data or object
we will use id function

memory organization for the data in the python


Refer the dia;

eg;
#Case-1
a=10
print(id(a))
print(a)

a=20
print(id(a))
print(a)

#Case-2
a=10
print(a)
print(id(a))

b=10
print(b)
print(id(b))

Fundamental datatypes;
-----------------------
1. int data type;
-------------------
eg;
a=10
print(a) #10
print(type(a)) # int

note : in python2 we have long datatype where as in python 3 we dont have long
datatype we just only int datatype.

we can represent int values in the fallowing ways;

1.Decimal form -->default format


2.Binary form
3.octal form
4.Hexa decimal form

1.Decimal format (base-10)


---------------------------
It is default number system in python
the allowed numbers are 0-9
eg;
a=25

2.Binary format (base-2)


---------------------------
The allowed numbers are 0-1
Literal value prefixed with 0b or 0B
eg;
a=ob1111
a=1111 -->decimal
a=0b1111 -->binary
a=0B1101
print(a)

3.octal format (base-8)


---------------------------
The allowed numbers are 0-7
Literal value prefixed with 0o or 0O
eg;
a=123
a=0o123
a=0O786 #8 is not in octal range
print(a)

4.Hexadecimal format (base-16)


---------------------------
The allowed numbers are 0-9 and a-f(both upper and lower case)
Literal value prefixed with 0x or 0X
eg;
a=349
a=0x349
a=0XBee
#a=0XBook
a=0XFACE
#a=0XBeer
print(a)

You might also like